{"version":3,"sources":["jsdelivr-header.js","/npm/bookshelf-touch@1.1.4/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,OAAO,QAAU,SAAS,GAExB,MAAM,EAAQ,EAAU,MAAM,UAE9B,EAAU,MAAQ,EAAU,MAAM,OAAO,CAEvC,YAAa,WACX,EAAM,YAAY,MAAM,KAAM,WAC9B,KAAK,GAAG,UAAU,IAAM,KAAK,SAC/B,EAEA,MAAO,WAEL,MAAM,EAAS,oBAAoB,MACnC,IAAK,IAAI,KAAa,EAAQ,CAC5B,MAAM,EAAkB,EAAO,GAC3B,GACF,eAAe,KAAM,GAA+B,IAApB,EAA2B,cAAc,GAAa,EAE1F,CACF,GAEJ,EAEA,MAAM,cAAgB,CACpB,WAAY,CAAC,EACb,WAAY,CACV,QAAS,GAAU,EAAO,IAAI,cAC9B,QAAQ,IAIZ,SAAS,eAAe,EAAQ,EAAW,GAEzC,MAAM,EAAQ,EAAO,IAAI,GACzB,GAAI,GAAS,EAAO,SAAW,EAAO,QAEpC,EAAO,IAAI,EAAW,IAAI,UACrB,IAAI,EAET,OAGA,EAAO,IAAI,EAAW,EAAO,SAAU,EAAO,QAAQ,IAAwB,IAAI,KACpF,CACF,CAEA,SAAS,oBAAoB,GAC3B,MAAM,EAAa,EAAO,WAC1B,GAAK,EAEE,IAAI,MAAM,QAAQ,GAAa,CAEpC,MAAM,EAAS,CAAC,EAChB,IAAK,IAAI,KAAY,cACf,EAAW,QAAQ,IAAa,IAClC,EAAO,GAAY,cAAc,IAIrC,OAAO,CACT,CAAO,GAA0B,iBAAhB,EACf,MAAO,CACL,CAAC,GAAa,cAAc,IAEzB,IAAmB,IAAf,EACT,OAAO,cACF,GAA0B,iBAAhB,EACf,OAAO,EAEP,MAAM,IAAI,MAAM,mEAAmE,KAAK,UAAU,cAAsB,KAC1H,CArBE,MAAO,CAAC,CAsBZ","file":"/npm/bookshelf-touch@1.1.4/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/bookshelf-touch@1.1.4/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","module.exports = function(bookshelf) {\n\n  const proto = bookshelf.Model.prototype;\n\n  bookshelf.Model = bookshelf.Model.extend({\n\n    constructor: function() {\n      proto.constructor.apply(this, arguments);\n      this.on('saving', () => this.touch());\n    },\n\n    touch: function() {\n\n      const config = getTimestampsConfig(this);\n      for (let timestamp in config) {\n        const timestampConfig = config[timestamp];\n        if (timestampConfig) {\n          touchTimestamp(this, timestamp, timestampConfig === true ? defaultConfig[timestamp] : timestampConfig);\n        }\n      }\n    }\n  });\n};\n\nconst defaultConfig = {\n  created_at: {},\n  updated_at: {\n    default: record => record.get('created_at'),\n    update: true\n  }\n};\n\nfunction touchTimestamp(record, timestamp, config) {\n\n  const isSet = record.get(timestamp);\n  if (isSet && config.update && !record.isNew()) {\n    // Update the timestamp (only if \"update\" is true).\n    record.set(timestamp, new Date());\n  } else if (isSet) {\n    // Do not do anything if the timestamp is already set and \"update\" is not true.\n    return;\n  } else {\n    // Initialize the timestamp if not set (to its default value or to now).\n    record.set(timestamp, config.default ? config.default(record) || new Date() : new Date());\n  }\n}\n\nfunction getTimestampsConfig(record) {\n  const timestamps = record.timestamps;\n  if (!timestamps) {\n    return {};\n  } else if (Array.isArray(timestamps)) {\n\n    const config = {};\n    for (let property in defaultConfig) {\n      if (timestamps.indexOf(property) >= 0) {\n        config[property] = defaultConfig[property];\n      }\n    }\n\n    return config;\n  } else if (typeof(timestamps) == 'string') {\n    return {\n      [timestamps]: defaultConfig[timestamps]\n    };\n  } else if (timestamps === true) {\n    return defaultConfig;\n  } else if (typeof(timestamps) == 'object') {\n    return timestamps;\n  } else {\n    throw new Error(`\"timestamps\" property should be true, a string or an array, got ${JSON.stringify(timestamps)} (${typeof(timestamps)})`);\n  }\n}\n"]}