@warp-drive/legacy 5.10.0-alpha.2 → 5.10.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -8
- package/blueprints/adapter/files/__root__/__path__/__name__.js +1 -0
- package/blueprints/adapter/index.js +27 -0
- package/blueprints/adapter-test/index.js +33 -0
- package/blueprints/adapter-test/qunit-files/__root__/__path__/__test__.js +1 -0
- package/blueprints/model/HELP.md +26 -0
- package/blueprints/model/files/__root__/__path__/__name__.js +1 -0
- package/blueprints/model/index.js +27 -0
- package/blueprints/model-test/index.js +33 -0
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +1 -0
- package/blueprints/serializer/files/__root__/__path__/__name__.js +1 -0
- package/blueprints/serializer/index.js +27 -0
- package/blueprints/serializer-test/index.js +33 -0
- package/blueprints/serializer-test/qunit-files/__root__/__path__/__test__.js +1 -0
- package/blueprints/transform/files/__root__/__path__/__name__.js +1 -0
- package/blueprints/transform/index.js +17 -0
- package/blueprints/transform-test/index.js +33 -0
- package/blueprints/transform-test/qunit-files/__root__/__path__/__test__.js +1 -0
- package/dist/{-private-DccRZQsm.js → -private-0_Oc-M3x.js} +10 -17
- package/dist/-private-0_Oc-M3x.js.map +1 -0
- package/dist/{-private-DQ6Iap2t.js → -private-L2BtGGYa.js} +8 -14
- package/dist/{-private-DQ6Iap2t.js.map → -private-L2BtGGYa.js.map} +1 -1
- package/dist/adapter/-private.d.ts +2 -12
- package/dist/adapter/-private.d.ts.map +1 -1
- package/dist/adapter/-private.js +1 -1
- package/dist/adapter/error.d.ts +1 -1
- package/dist/adapter/error.js +54 -2
- package/dist/adapter/error.js.map +1 -1
- package/dist/adapter/json-api.d.ts +5 -5
- package/dist/adapter/json-api.d.ts.map +1 -1
- package/dist/adapter/json-api.js +10 -4
- package/dist/adapter/json-api.js.map +1 -1
- package/dist/adapter/rest.d.ts +1 -1
- package/dist/adapter/rest.js +23 -5
- package/dist/adapter/rest.js.map +1 -1
- package/dist/{adapter-eYo2pIuM.js → adapter-AwGvdMSZ.js} +45 -6
- package/dist/adapter-AwGvdMSZ.js.map +1 -0
- package/dist/{adapter-CARrK3-8.d.ts → adapter-DvDVeaCc.d.ts} +9 -6
- package/dist/adapter-DvDVeaCc.d.ts.map +1 -0
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.js +1 -1
- package/dist/compat/-private.d.ts +1 -1
- package/dist/compat/-private.js +1 -1
- package/dist/compat/builders.d.ts +10 -8
- package/dist/compat/builders.d.ts.map +1 -1
- package/dist/compat/builders.js +15 -9
- package/dist/compat/builders.js.map +1 -1
- package/dist/compat/extensions.d.ts +1 -1
- package/dist/compat/extensions.js +23 -2
- package/dist/compat/extensions.js.map +1 -1
- package/dist/compat/utils.d.ts +17 -2
- package/dist/compat/utils.d.ts.map +1 -1
- package/dist/compat/utils.js +19 -2
- package/dist/compat/utils.js.map +1 -1
- package/dist/{compat-DcHVxuuZ.js → compat-C-yQnbkF.js} +61 -8
- package/dist/compat-C-yQnbkF.js.map +1 -0
- package/dist/{compat-BbNNmTM-.d.ts → compat-DoWEarkU.d.ts} +30 -17
- package/dist/compat-DoWEarkU.d.ts.map +1 -0
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +1 -1
- package/dist/{error-CzkyXr1Q.d.ts → error-798wGD3r.d.ts} +49 -3
- package/dist/error-798wGD3r.d.ts.map +1 -0
- package/dist/{errors-CS110tMl.js → errors-BEExAZtv.js} +42 -32
- package/dist/errors-BEExAZtv.js.map +1 -0
- package/dist/{extensions-DumNm4dA.d.ts → extensions-DcEz1lKv.d.ts} +18 -3
- package/dist/extensions-DcEz1lKv.d.ts.map +1 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -7
- package/dist/index.js.map +1 -1
- package/dist/{json-BXNPTlcH.js → json-Baaga4BP.js} +10 -5
- package/dist/json-Baaga4BP.js.map +1 -0
- package/dist/model/-private.d.ts +1 -1
- package/dist/model/-private.js +1 -1
- package/dist/model/migration-support.d.ts +19 -4
- package/dist/model/migration-support.d.ts.map +1 -1
- package/dist/model/migration-support.js +25 -7
- package/dist/model/migration-support.js.map +1 -1
- package/dist/{model-DWH9f__L.js → model-Be-e84FX.js} +19 -12
- package/dist/model-Be-e84FX.js.map +1 -0
- package/dist/{model-62hn5_PD.d.ts → model-DAdY1ibr.d.ts} +13 -26
- package/dist/model-DAdY1ibr.d.ts.map +1 -0
- package/dist/{unpkg/dev-deprecated/model-fragments-DSqu0ptR.js → model-fragments-DCHMDr5f.js} +32 -18
- package/dist/model-fragments-DCHMDr5f.js.map +1 -0
- package/dist/model-fragments.d.ts +31 -19
- package/dist/model-fragments.d.ts.map +1 -1
- package/dist/model-fragments.js +1 -1
- package/dist/model.d.ts +12 -11
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -2
- package/dist/{rest-0NhtexIq.d.ts → rest-CmFneLJH.d.ts} +18 -8
- package/dist/rest-CmFneLJH.d.ts.map +1 -0
- package/dist/{runtime--fcdnjmJ-DMTJ0Kb3.js → runtime--fcdnjmJ-5yaSpa-d.js} +2 -3
- package/dist/{runtime--fcdnjmJ-DMTJ0Kb3.js.map → runtime--fcdnjmJ-5yaSpa-d.js.map} +1 -1
- package/dist/{schema-provider-DguGmQDS.js → schema-provider-BAB8DyMr.js} +22 -21
- package/dist/schema-provider-BAB8DyMr.js.map +1 -0
- package/dist/serializer/json-api.d.ts +1 -2
- package/dist/serializer/json-api.d.ts.map +1 -1
- package/dist/serializer/json-api.js +7 -3
- package/dist/serializer/json-api.js.map +1 -1
- package/dist/serializer/json.d.ts +2 -2
- package/dist/serializer/json.d.ts.map +1 -1
- package/dist/serializer/json.js +1 -1
- package/dist/serializer/rest.d.ts +4 -4
- package/dist/serializer/rest.d.ts.map +1 -1
- package/dist/serializer/rest.js +12 -5
- package/dist/serializer/rest.js.map +1 -1
- package/dist/serializer/transform.d.ts +9 -10
- package/dist/serializer/transform.d.ts.map +1 -1
- package/dist/serializer/transform.js +14 -10
- package/dist/serializer/transform.js.map +1 -1
- package/dist/serializer.d.ts +2 -2
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +42 -3
- package/dist/serializer.js.map +1 -1
- package/dist/{store-C4qYzXei.js → store-BLKEsJyw.js} +13 -7
- package/dist/store-BLKEsJyw.js.map +1 -0
- package/dist/store.d.ts +3 -2
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +1 -1
- package/dist/unpkg/dev/{-private-CrEyBE-B.js → -private-BprUAEe_.js} +8 -14
- package/dist/unpkg/{dev-deprecated/-private-CrEyBE-B.js.map → dev/-private-BprUAEe_.js.map} +1 -1
- package/dist/unpkg/dev/{-private-vOhxVExH.js → -private-Dch4SxkU.js} +10 -17
- package/dist/unpkg/dev/-private-Dch4SxkU.js.map +1 -0
- package/dist/unpkg/dev/adapter/-private.js +1 -1
- package/dist/unpkg/dev/adapter/error.js +54 -2
- package/dist/unpkg/dev/adapter/error.js.map +1 -1
- package/dist/unpkg/dev/adapter/json-api.js +10 -4
- package/dist/unpkg/dev/adapter/json-api.js.map +1 -1
- package/dist/unpkg/dev/adapter/rest.js +23 -5
- package/dist/unpkg/dev/adapter/rest.js.map +1 -1
- package/dist/unpkg/dev/{adapter-oLwyr47q.js → adapter-BAn4SeUA.js} +45 -6
- package/dist/unpkg/dev/adapter-BAn4SeUA.js.map +1 -0
- package/dist/unpkg/dev/adapter.js +1 -1
- package/dist/unpkg/dev/compat/-private.js +1 -1
- package/dist/unpkg/dev/compat/builders.js +15 -9
- package/dist/unpkg/dev/compat/builders.js.map +1 -1
- package/dist/unpkg/dev/compat/extensions.js +23 -2
- package/dist/unpkg/dev/compat/extensions.js.map +1 -1
- package/dist/unpkg/dev/compat/utils.js +19 -2
- package/dist/unpkg/dev/compat/utils.js.map +1 -1
- package/dist/unpkg/dev/{compat-DNQT2TQx.js → compat-BdovRRzQ.js} +62 -10
- package/dist/unpkg/dev/compat-BdovRRzQ.js.map +1 -0
- package/dist/unpkg/dev/compat.js +1 -1
- package/dist/unpkg/dev/{errors-DnzvLM2A.js → errors-CGvbM6WH.js} +42 -32
- package/dist/unpkg/dev/errors-CGvbM6WH.js.map +1 -0
- package/dist/unpkg/dev/index.js +25 -7
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/{dev-deprecated/json-DDJji3V3.js → dev/json-BlSBe84o.js} +10 -5
- package/dist/unpkg/dev/json-BlSBe84o.js.map +1 -0
- package/dist/unpkg/dev/model/-private.js +1 -1
- package/dist/unpkg/dev/model/migration-support.js +24 -6
- package/dist/unpkg/dev/model/migration-support.js.map +1 -1
- package/dist/unpkg/dev/{model-BxPIR7m2.js → model-QCZr8eec.js} +19 -12
- package/dist/unpkg/dev/model-QCZr8eec.js.map +1 -0
- package/dist/{model-fragments-DSqu0ptR.js → unpkg/dev/model-fragments-DCHMDr5f.js} +32 -18
- package/dist/unpkg/dev/model-fragments-DCHMDr5f.js.map +1 -0
- package/dist/unpkg/dev/model-fragments.js +1 -1
- package/dist/unpkg/dev/model.js +2 -2
- package/dist/unpkg/dev/{runtime--fcdnjmJ-DMTJ0Kb3.js → runtime--fcdnjmJ-5yaSpa-d.js} +2 -3
- package/dist/unpkg/dev/{runtime--fcdnjmJ-DMTJ0Kb3.js.map → runtime--fcdnjmJ-5yaSpa-d.js.map} +1 -1
- package/dist/unpkg/dev/{schema-provider-CI_a48ja.js → schema-provider-IMFO9Kgw.js} +18 -17
- package/dist/unpkg/dev/schema-provider-IMFO9Kgw.js.map +1 -0
- package/dist/unpkg/dev/serializer/json-api.js +7 -3
- package/dist/unpkg/dev/serializer/json-api.js.map +1 -1
- package/dist/unpkg/dev/serializer/json.js +1 -1
- package/dist/unpkg/dev/serializer/rest.js +12 -5
- package/dist/unpkg/dev/serializer/rest.js.map +1 -1
- package/dist/unpkg/dev/serializer/transform.js +14 -10
- package/dist/unpkg/dev/serializer/transform.js.map +1 -1
- package/dist/unpkg/dev/serializer.js +42 -3
- package/dist/unpkg/dev/serializer.js.map +1 -1
- package/dist/unpkg/dev/{store-D_V8-HQl.js → store-BiXsLLAu.js} +13 -7
- package/dist/unpkg/dev/store-BiXsLLAu.js.map +1 -0
- package/dist/unpkg/dev/store.js +1 -1
- package/dist/unpkg/dev/{util-dSKEgQDp.js → util-CI7b4vAE.js} +2 -3
- package/dist/unpkg/dev/{util-dSKEgQDp.js.map → util-CI7b4vAE.js.map} +1 -1
- package/dist/unpkg/{prod/utils-DYC9utVJ.js → dev/utils-_O0MjUTU.js} +2 -3
- package/dist/unpkg/dev/{utils-DYC9utVJ.js.map → utils-_O0MjUTU.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{-private-CrEyBE-B.js → -private-BprUAEe_.js} +8 -14
- package/dist/unpkg/{dev/-private-CrEyBE-B.js.map → dev-deprecated/-private-BprUAEe_.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{-private-vOhxVExH.js → -private-Dch4SxkU.js} +10 -17
- package/dist/unpkg/dev-deprecated/-private-Dch4SxkU.js.map +1 -0
- package/dist/unpkg/dev-deprecated/adapter/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/adapter/error.js +54 -2
- package/dist/unpkg/dev-deprecated/adapter/error.js.map +1 -1
- package/dist/unpkg/dev-deprecated/adapter/json-api.js +10 -4
- package/dist/unpkg/dev-deprecated/adapter/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/adapter/rest.js +23 -5
- package/dist/unpkg/dev-deprecated/adapter/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{adapter-oLwyr47q.js → adapter-BAn4SeUA.js} +45 -6
- package/dist/unpkg/dev-deprecated/adapter-BAn4SeUA.js.map +1 -0
- package/dist/unpkg/dev-deprecated/adapter.js +1 -1
- package/dist/unpkg/dev-deprecated/compat/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/compat/builders.js +15 -9
- package/dist/unpkg/dev-deprecated/compat/builders.js.map +1 -1
- package/dist/unpkg/dev-deprecated/compat/extensions.js +23 -2
- package/dist/unpkg/dev-deprecated/compat/extensions.js.map +1 -1
- package/dist/unpkg/dev-deprecated/compat/utils.js +19 -2
- package/dist/unpkg/dev-deprecated/compat/utils.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{compat-CeT0PnVX.js → compat-CPVriwH0.js} +62 -10
- package/dist/unpkg/dev-deprecated/compat-CPVriwH0.js.map +1 -0
- package/dist/unpkg/dev-deprecated/compat.js +1 -1
- package/dist/unpkg/dev-deprecated/{errors-jHQESeNQ.js → errors-yPc7D7r3.js} +42 -32
- package/dist/unpkg/dev-deprecated/errors-yPc7D7r3.js.map +1 -0
- package/dist/unpkg/dev-deprecated/index.js +25 -7
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/{dev/json-DDJji3V3.js → dev-deprecated/json-BlSBe84o.js} +10 -5
- package/dist/unpkg/dev-deprecated/json-BlSBe84o.js.map +1 -0
- package/dist/unpkg/dev-deprecated/model/-private.js +1 -1
- package/dist/unpkg/dev-deprecated/model/migration-support.js +24 -6
- package/dist/unpkg/dev-deprecated/model/migration-support.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{model-BeGORt6h.js → model-B0ZNLaHO.js} +19 -12
- package/dist/unpkg/dev-deprecated/model-B0ZNLaHO.js.map +1 -0
- package/dist/unpkg/{prod-deprecated/model-fragments-DSqu0ptR.js → dev-deprecated/model-fragments-DCHMDr5f.js} +32 -18
- package/dist/unpkg/dev-deprecated/model-fragments-DCHMDr5f.js.map +1 -0
- package/dist/unpkg/dev-deprecated/model-fragments.js +1 -1
- package/dist/unpkg/dev-deprecated/model.js +2 -2
- package/dist/unpkg/dev-deprecated/{runtime--fcdnjmJ-DMTJ0Kb3.js → runtime--fcdnjmJ-5yaSpa-d.js} +2 -3
- package/dist/unpkg/dev-deprecated/{runtime--fcdnjmJ-DMTJ0Kb3.js.map → runtime--fcdnjmJ-5yaSpa-d.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{schema-provider-NmtdR4n_.js → schema-provider-DGWYnFno.js} +18 -17
- package/dist/unpkg/dev-deprecated/schema-provider-DGWYnFno.js.map +1 -0
- package/dist/unpkg/dev-deprecated/serializer/json-api.js +7 -3
- package/dist/unpkg/dev-deprecated/serializer/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/dev-deprecated/serializer/rest.js +12 -5
- package/dist/unpkg/dev-deprecated/serializer/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/serializer/transform.js +14 -10
- package/dist/unpkg/dev-deprecated/serializer/transform.js.map +1 -1
- package/dist/unpkg/dev-deprecated/serializer.js +42 -3
- package/dist/unpkg/dev-deprecated/serializer.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{store-BCOLSC6z.js → store-Ci8k7Lh6.js} +13 -7
- package/dist/unpkg/dev-deprecated/store-Ci8k7Lh6.js.map +1 -0
- package/dist/unpkg/dev-deprecated/store.js +1 -1
- package/dist/unpkg/dev-deprecated/{util-CXA3RNYH.js → util-DL_8JecH.js} +2 -3
- package/dist/unpkg/dev-deprecated/{util-CXA3RNYH.js.map → util-DL_8JecH.js.map} +1 -1
- package/dist/unpkg/dev-deprecated/{utils-DQkMqhDv.js → utils-DyGjRZ14.js} +2 -3
- package/dist/unpkg/dev-deprecated/{utils-DQkMqhDv.js.map → utils-DyGjRZ14.js.map} +1 -1
- package/dist/unpkg/{prod-deprecated/-private-B4bxoTuK.js → prod/-private-Dc9yg98O.js} +8 -14
- package/dist/unpkg/{prod-deprecated/-private-B4bxoTuK.js.map → prod/-private-Dc9yg98O.js.map} +1 -1
- package/dist/unpkg/prod/{-private-SfXkkHKd.js → -private-DuRzYAyW.js} +9 -15
- package/dist/unpkg/prod/-private-DuRzYAyW.js.map +1 -0
- package/dist/unpkg/prod/adapter/-private.js +1 -1
- package/dist/unpkg/prod/adapter/error.js +54 -2
- package/dist/unpkg/prod/adapter/error.js.map +1 -1
- package/dist/unpkg/prod/adapter/json-api.js +10 -4
- package/dist/unpkg/prod/adapter/json-api.js.map +1 -1
- package/dist/unpkg/prod/adapter/rest.js +23 -5
- package/dist/unpkg/prod/adapter/rest.js.map +1 -1
- package/dist/unpkg/prod/{adapter-DQ9UA7FC.js → adapter-D0HCLrwm.js} +45 -6
- package/dist/unpkg/prod/adapter-D0HCLrwm.js.map +1 -0
- package/dist/unpkg/prod/adapter.js +1 -1
- package/dist/unpkg/prod/compat/-private.js +1 -1
- package/dist/unpkg/prod/compat/builders.js +15 -9
- package/dist/unpkg/prod/compat/builders.js.map +1 -1
- package/dist/unpkg/prod/compat/extensions.js +23 -2
- package/dist/unpkg/prod/compat/extensions.js.map +1 -1
- package/dist/unpkg/prod/compat/utils.js +19 -2
- package/dist/unpkg/prod/compat/utils.js.map +1 -1
- package/dist/unpkg/{prod-deprecated/compat-DxiVkCUb.js → prod/compat-PrUuencH.js} +62 -10
- package/dist/unpkg/prod/compat-PrUuencH.js.map +1 -0
- package/dist/unpkg/prod/compat.js +1 -1
- package/dist/unpkg/prod/{errors-DQDfNqVx.js → errors-Bw8niCo8.js} +38 -27
- package/dist/unpkg/prod/errors-Bw8niCo8.js.map +1 -0
- package/dist/unpkg/prod/index.js +25 -7
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/{json-BD1kRTfB.js → json-D1bH8enA.js} +10 -5
- package/dist/unpkg/prod/json-D1bH8enA.js.map +1 -0
- package/dist/unpkg/prod/model/-private.js +1 -1
- package/dist/unpkg/prod/model/migration-support.js +24 -6
- package/dist/unpkg/prod/model/migration-support.js.map +1 -1
- package/dist/unpkg/prod/{model-CYMA-e_S.js → model-QtC0IWbE.js} +19 -12
- package/dist/unpkg/prod/model-QtC0IWbE.js.map +1 -0
- package/dist/unpkg/prod/model-fragments-DCHMDr5f.js +348 -0
- package/dist/unpkg/prod/model-fragments-DCHMDr5f.js.map +1 -0
- package/dist/unpkg/prod/model-fragments.js +1 -1
- package/dist/unpkg/prod/model.js +2 -2
- package/dist/unpkg/prod/runtime--fcdnjmJ-5yaSpa-d.js +52 -0
- package/dist/unpkg/prod/{runtime--fcdnjmJ-DMTJ0Kb3.js.map → runtime--fcdnjmJ-5yaSpa-d.js.map} +1 -1
- package/dist/unpkg/prod/{schema-provider-05U1H-Kl.js → schema-provider-DPOzTa8e.js} +18 -17
- package/dist/unpkg/prod/schema-provider-DPOzTa8e.js.map +1 -0
- package/dist/unpkg/prod/serializer/json-api.js +7 -3
- package/dist/unpkg/prod/serializer/json-api.js.map +1 -1
- package/dist/unpkg/prod/serializer/json.js +1 -1
- package/dist/unpkg/prod/serializer/rest.js +12 -5
- package/dist/unpkg/prod/serializer/rest.js.map +1 -1
- package/dist/unpkg/prod/serializer/transform.js +14 -10
- package/dist/unpkg/prod/serializer/transform.js.map +1 -1
- package/dist/unpkg/prod/serializer.js +42 -3
- package/dist/unpkg/prod/serializer.js.map +1 -1
- package/dist/unpkg/{prod-deprecated/store-0L2CkYzh.js → prod/store-BsSkzWgk.js} +13 -7
- package/dist/unpkg/{prod-deprecated/store-0L2CkYzh.js.map → prod/store-BsSkzWgk.js.map} +1 -1
- package/dist/unpkg/prod/store.js +1 -1
- package/dist/unpkg/prod/{util-dSKEgQDp.js → util-CI7b4vAE.js} +2 -3
- package/dist/unpkg/prod/{util-dSKEgQDp.js.map → util-CI7b4vAE.js.map} +1 -1
- package/dist/unpkg/{dev/utils-DYC9utVJ.js → prod/utils-_O0MjUTU.js} +2 -3
- package/dist/unpkg/prod/{utils-DYC9utVJ.js.map → utils-_O0MjUTU.js.map} +1 -1
- package/dist/unpkg/{prod/-private-B4bxoTuK.js → prod-deprecated/-private-Dc9yg98O.js} +8 -14
- package/dist/unpkg/{prod/-private-B4bxoTuK.js.map → prod-deprecated/-private-Dc9yg98O.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/{-private-SfXkkHKd.js → -private-DuRzYAyW.js} +9 -15
- package/dist/unpkg/prod-deprecated/-private-DuRzYAyW.js.map +1 -0
- package/dist/unpkg/prod-deprecated/adapter/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/adapter/error.js +54 -2
- package/dist/unpkg/prod-deprecated/adapter/error.js.map +1 -1
- package/dist/unpkg/prod-deprecated/adapter/json-api.js +10 -4
- package/dist/unpkg/prod-deprecated/adapter/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/adapter/rest.js +23 -5
- package/dist/unpkg/prod-deprecated/adapter/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{adapter-DQ9UA7FC.js → adapter-D0HCLrwm.js} +45 -6
- package/dist/unpkg/prod-deprecated/adapter-D0HCLrwm.js.map +1 -0
- package/dist/unpkg/prod-deprecated/adapter.js +1 -1
- package/dist/unpkg/prod-deprecated/compat/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/compat/builders.js +15 -9
- package/dist/unpkg/prod-deprecated/compat/builders.js.map +1 -1
- package/dist/unpkg/prod-deprecated/compat/extensions.js +23 -2
- package/dist/unpkg/prod-deprecated/compat/extensions.js.map +1 -1
- package/dist/unpkg/prod-deprecated/compat/utils.js +19 -2
- package/dist/unpkg/prod-deprecated/compat/utils.js.map +1 -1
- package/dist/unpkg/{prod/compat-DxiVkCUb.js → prod-deprecated/compat-PrUuencH.js} +62 -10
- package/dist/unpkg/prod-deprecated/compat-PrUuencH.js.map +1 -0
- package/dist/unpkg/prod-deprecated/compat.js +1 -1
- package/dist/unpkg/prod-deprecated/{errors-ii4L43_1.js → errors-D20lKboZ.js} +38 -27
- package/dist/unpkg/prod-deprecated/errors-D20lKboZ.js.map +1 -0
- package/dist/unpkg/prod-deprecated/index.js +25 -7
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{json-BD1kRTfB.js → json-D1bH8enA.js} +10 -5
- package/dist/unpkg/prod-deprecated/json-D1bH8enA.js.map +1 -0
- package/dist/unpkg/prod-deprecated/model/-private.js +1 -1
- package/dist/unpkg/prod-deprecated/model/migration-support.js +24 -6
- package/dist/unpkg/prod-deprecated/model/migration-support.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{model-D3oCPHtM.js → model-B946S2pl.js} +19 -12
- package/dist/unpkg/prod-deprecated/model-B946S2pl.js.map +1 -0
- package/dist/unpkg/{dev/model-fragments-DSqu0ptR.js → prod-deprecated/model-fragments-DCHMDr5f.js} +32 -18
- package/dist/unpkg/prod-deprecated/model-fragments-DCHMDr5f.js.map +1 -0
- package/dist/unpkg/prod-deprecated/model-fragments.js +1 -1
- package/dist/unpkg/prod-deprecated/model.js +2 -2
- package/dist/unpkg/prod-deprecated/{runtime--fcdnjmJ-DMTJ0Kb3.js → runtime--fcdnjmJ-5yaSpa-d.js} +2 -3
- package/dist/unpkg/prod-deprecated/{runtime--fcdnjmJ-DMTJ0Kb3.js.map → runtime--fcdnjmJ-5yaSpa-d.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/{schema-provider-CKH_bnnS.js → schema-provider-xcaytn9y.js} +18 -17
- package/dist/unpkg/prod-deprecated/schema-provider-xcaytn9y.js.map +1 -0
- package/dist/unpkg/prod-deprecated/serializer/json-api.js +7 -3
- package/dist/unpkg/prod-deprecated/serializer/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/serializer/json.js +1 -1
- package/dist/unpkg/prod-deprecated/serializer/rest.js +12 -5
- package/dist/unpkg/prod-deprecated/serializer/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/serializer/transform.js +14 -10
- package/dist/unpkg/prod-deprecated/serializer/transform.js.map +1 -1
- package/dist/unpkg/prod-deprecated/serializer.js +42 -3
- package/dist/unpkg/prod-deprecated/serializer.js.map +1 -1
- package/dist/unpkg/{prod/store-RGGc1ilN.js → prod-deprecated/store-Dsw2f4s-.js} +13 -7
- package/dist/unpkg/{prod/store-RGGc1ilN.js.map → prod-deprecated/store-Dsw2f4s-.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/store.js +1 -1
- package/dist/unpkg/prod-deprecated/{util-CQQdHX3n.js → util-CVu5_VeN.js} +2 -3
- package/dist/unpkg/prod-deprecated/{util-CQQdHX3n.js.map → util-CVu5_VeN.js.map} +1 -1
- package/dist/unpkg/prod-deprecated/{utils-BMI_JwFP.js → utils-z1h-zTls.js} +2 -3
- package/dist/unpkg/prod-deprecated/{utils-BMI_JwFP.js.map → utils-z1h-zTls.js.map} +1 -1
- package/dist/{util-Bnx8nm-D.js → util-fMuLguoj.js} +2 -3
- package/dist/{util-Bnx8nm-D.js.map → util-fMuLguoj.js.map} +1 -1
- package/dist/{utils-ZAytYep8.js → utils-UqBsN9IU.js} +2 -3
- package/dist/{utils-ZAytYep8.js.map → utils-UqBsN9IU.js.map} +1 -1
- package/logos/README.md +1 -1
- package/package.json +17 -12
- package/dist/-private-DccRZQsm.js.map +0 -1
- package/dist/adapter-CARrK3-8.d.ts.map +0 -1
- package/dist/adapter-eYo2pIuM.js.map +0 -1
- package/dist/compat-BbNNmTM-.d.ts.map +0 -1
- package/dist/compat-DcHVxuuZ.js.map +0 -1
- package/dist/error-CzkyXr1Q.d.ts.map +0 -1
- package/dist/errors-CS110tMl.js.map +0 -1
- package/dist/extensions-DumNm4dA.d.ts.map +0 -1
- package/dist/json-BXNPTlcH.js.map +0 -1
- package/dist/model-62hn5_PD.d.ts.map +0 -1
- package/dist/model-DWH9f__L.js.map +0 -1
- package/dist/model-fragments-DSqu0ptR.js.map +0 -1
- package/dist/rest-0NhtexIq.d.ts.map +0 -1
- package/dist/schema-provider-DguGmQDS.js.map +0 -1
- package/dist/store-C4qYzXei.js.map +0 -1
- package/dist/unpkg/dev/-private-vOhxVExH.js.map +0 -1
- package/dist/unpkg/dev/adapter-oLwyr47q.js.map +0 -1
- package/dist/unpkg/dev/compat-DNQT2TQx.js.map +0 -1
- package/dist/unpkg/dev/errors-DnzvLM2A.js.map +0 -1
- package/dist/unpkg/dev/json-DDJji3V3.js.map +0 -1
- package/dist/unpkg/dev/model-BxPIR7m2.js.map +0 -1
- package/dist/unpkg/dev/model-fragments-DSqu0ptR.js.map +0 -1
- package/dist/unpkg/dev/schema-provider-CI_a48ja.js.map +0 -1
- package/dist/unpkg/dev/store-D_V8-HQl.js.map +0 -1
- package/dist/unpkg/dev-deprecated/-private-vOhxVExH.js.map +0 -1
- package/dist/unpkg/dev-deprecated/adapter-oLwyr47q.js.map +0 -1
- package/dist/unpkg/dev-deprecated/compat-CeT0PnVX.js.map +0 -1
- package/dist/unpkg/dev-deprecated/errors-jHQESeNQ.js.map +0 -1
- package/dist/unpkg/dev-deprecated/json-DDJji3V3.js.map +0 -1
- package/dist/unpkg/dev-deprecated/model-BeGORt6h.js.map +0 -1
- package/dist/unpkg/dev-deprecated/model-fragments-DSqu0ptR.js.map +0 -1
- package/dist/unpkg/dev-deprecated/schema-provider-NmtdR4n_.js.map +0 -1
- package/dist/unpkg/dev-deprecated/store-BCOLSC6z.js.map +0 -1
- package/dist/unpkg/prod/-private-SfXkkHKd.js.map +0 -1
- package/dist/unpkg/prod/adapter-DQ9UA7FC.js.map +0 -1
- package/dist/unpkg/prod/compat-DxiVkCUb.js.map +0 -1
- package/dist/unpkg/prod/errors-DQDfNqVx.js.map +0 -1
- package/dist/unpkg/prod/json-BD1kRTfB.js.map +0 -1
- package/dist/unpkg/prod/model-CYMA-e_S.js.map +0 -1
- package/dist/unpkg/prod/model-fragments-DSqu0ptR.js +0 -334
- package/dist/unpkg/prod/model-fragments-DSqu0ptR.js.map +0 -1
- package/dist/unpkg/prod/runtime--fcdnjmJ-DMTJ0Kb3.js +0 -53
- package/dist/unpkg/prod/schema-provider-05U1H-Kl.js.map +0 -1
- package/dist/unpkg/prod-deprecated/-private-SfXkkHKd.js.map +0 -1
- package/dist/unpkg/prod-deprecated/adapter-DQ9UA7FC.js.map +0 -1
- package/dist/unpkg/prod-deprecated/compat-DxiVkCUb.js.map +0 -1
- package/dist/unpkg/prod-deprecated/errors-ii4L43_1.js.map +0 -1
- package/dist/unpkg/prod-deprecated/json-BD1kRTfB.js.map +0 -1
- package/dist/unpkg/prod-deprecated/model-D3oCPHtM.js.map +0 -1
- package/dist/unpkg/prod-deprecated/model-fragments-DSqu0ptR.js.map +0 -1
- package/dist/unpkg/prod-deprecated/schema-provider-CKH_bnnS.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EmberObject from "@ember/object";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// src/serializer/-private/transforms/transform.ts
|
|
4
4
|
/**
|
|
5
5
|
The `Transform` class is used to serialize and deserialize model
|
|
6
6
|
attributes when they are saved or loaded from an
|
|
@@ -75,13 +75,14 @@ return new this();
|
|
|
75
75
|
}
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
@summary Legacy base for custom attribute transforms, which implement `serialize` and `deserialize` to convert
|
|
79
|
+
values between payloads and records.
|
|
78
80
|
@class Transform
|
|
79
81
|
@public
|
|
80
82
|
*/
|
|
81
83
|
const Transform = EmberObject;
|
|
82
84
|
|
|
83
|
-
|
|
84
|
-
//#region src/serializer/-private/transforms/boolean.ts
|
|
85
|
+
// src/serializer/-private/transforms/boolean.ts
|
|
85
86
|
/**
|
|
86
87
|
The `BooleanTransform` class is used to serialize and deserialize
|
|
87
88
|
boolean attributes on Ember Data record objects. This transform is
|
|
@@ -114,6 +115,8 @@ export default class UserModel extends Model {
|
|
|
114
115
|
}
|
|
115
116
|
```
|
|
116
117
|
|
|
118
|
+
@summary Legacy transform for `attr('boolean')` that converts payload values to and from booleans, optionally
|
|
119
|
+
allowing `null`.
|
|
117
120
|
@public
|
|
118
121
|
*/
|
|
119
122
|
var BooleanTransform = class {
|
|
@@ -143,8 +146,7 @@ var BooleanTransform = class {
|
|
|
143
146
|
}
|
|
144
147
|
};
|
|
145
148
|
|
|
146
|
-
|
|
147
|
-
//#region src/serializer/-private/transforms/date.ts
|
|
149
|
+
// src/serializer/-private/transforms/date.ts
|
|
148
150
|
/**
|
|
149
151
|
The `DateTransform` class is used to serialize and deserialize
|
|
150
152
|
date attributes on Ember Data record objects. This transform is used
|
|
@@ -162,6 +164,8 @@ export default class ScoreModel extends Model {
|
|
|
162
164
|
}
|
|
163
165
|
```
|
|
164
166
|
|
|
167
|
+
@summary Legacy transform for `attr('date')` that converts ISO 8601 strings or epoch numbers to `Date` objects and
|
|
168
|
+
serializes them back to ISO 8601 strings.
|
|
165
169
|
@public
|
|
166
170
|
*/
|
|
167
171
|
var DateTransform = class {
|
|
@@ -197,8 +201,7 @@ var DateTransform = class {
|
|
|
197
201
|
}
|
|
198
202
|
};
|
|
199
203
|
|
|
200
|
-
|
|
201
|
-
//#region src/serializer/-private/transforms/number.ts
|
|
204
|
+
// src/serializer/-private/transforms/number.ts
|
|
202
205
|
function isNumber(value) {
|
|
203
206
|
return value === value && value !== Infinity && value !== -Infinity;
|
|
204
207
|
}
|
|
@@ -220,6 +223,8 @@ export default class ScoreModel extends Model {
|
|
|
220
223
|
}
|
|
221
224
|
```
|
|
222
225
|
|
|
226
|
+
@summary Legacy transform for `attr('number')` that converts payload values to numbers, or `null` when empty or not
|
|
227
|
+
a valid number.
|
|
223
228
|
@public
|
|
224
229
|
*/
|
|
225
230
|
var NumberTransform = class {
|
|
@@ -252,8 +257,7 @@ var NumberTransform = class {
|
|
|
252
257
|
}
|
|
253
258
|
};
|
|
254
259
|
|
|
255
|
-
|
|
256
|
-
//#region src/serializer/-private/transforms/string.ts
|
|
260
|
+
// src/serializer/-private/transforms/string.ts
|
|
257
261
|
/**
|
|
258
262
|
The `StringTransform` class is used to serialize and deserialize
|
|
259
263
|
string attributes on Ember Data record objects. This transform is
|
|
@@ -272,6 +276,7 @@ export default class UserModel extends Model {
|
|
|
272
276
|
}
|
|
273
277
|
```
|
|
274
278
|
|
|
279
|
+
@summary Legacy transform for `attr('string')` that converts payload values to and from strings.
|
|
275
280
|
@public
|
|
276
281
|
*/
|
|
277
282
|
var StringTransform = class {
|
|
@@ -296,6 +301,5 @@ var StringTransform = class {
|
|
|
296
301
|
}
|
|
297
302
|
};
|
|
298
303
|
|
|
299
|
-
//#endregion
|
|
300
304
|
export { BooleanTransform, DateTransform, NumberTransform, StringTransform, Transform };
|
|
301
305
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","names":["EmberObject","Transform","BooleanTransform","deserialize","serialized","options","undefined","allowNull","test","serialize","deserialized","Boolean","create","DateTransform","deserialize","serialized","_options","offset","indexOf","length","Date","slice","undefined","serialize","date","isNaN","toISOString","create","isNumber","value","Infinity","NumberTransform","deserialize","serialized","_options","undefined","transformed","Number","serialize","deserialized","create","StringTransform","deserialize","serialized","_options","String","serialize","deserialized","create"],"sources":["../../../../src/serializer/-private/transforms/transform.ts","../../../../src/serializer/-private/transforms/boolean.ts","../../../../src/serializer/-private/transforms/date.ts","../../../../src/serializer/-private/transforms/number.ts","../../../../src/serializer/-private/transforms/string.ts"],"sourcesContent":["import EmberObject from '@ember/object';\n\nimport type { LegacyAttributeField } from '@warp-drive/core/types/schema/fields';\n\nexport interface Transform {\n /**\n When given a deserialized value from a record attribute this\n method must return the serialized value.\n\n Example\n\n ```javascript\n serialize(deserialized, options) {\n return deserialized ? null : Number(deserialized);\n }\n ```\n\n @public\n @param deserialized The deserialized value\n @param options hash of options passed to `attr`\n @return The serialized value\n */\n serialize(value: unknown, options: LegacyAttributeField['options']): unknown;\n\n /**\n When given a serialized value from a JSON object this method must\n return the deserialized value for the record attribute.\n\n Example\n\n ```javascript\n deserialize(serialized, options) {\n return empty(serialized) ? null : Number(serialized);\n }\n ```\n\n @public\n @param serialized The serialized value\n @param options hash of options passed to `attr`\n @return The deserialized value\n */\n deserialize(value: unknown, options: LegacyAttributeField['options']): unknown;\n}\n\n/**\n The `Transform` class is used to serialize and deserialize model\n attributes when they are saved or loaded from an\n adapter. Subclassing `Transform` is useful for creating custom\n attributes. All subclasses of `Transform` must implement a\n `serialize` and a `deserialize` method.\n\n Example\n\n ```js [app/transforms/temperature.js]\n\n // Converts centigrade in the JSON to fahrenheit in the app\n export default class TemperatureTransform {\n deserialize(serialized, options) {\n return (serialized * 1.8) + 32;\n }\n\n serialize(deserialized, options) {\n return (deserialized - 32) / 1.8;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n Usage\n\n ```js [app/models/requirement.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class RequirementModel extends Model {\n @attr('string') name;\n @attr('temperature') temperature;\n }\n ```\n\n The options passed into the `attr` function when the attribute is\n declared on the model is also available in the transform.\n\n ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('string') title;\n @attr('markdown', {\n markdown: {\n gfm: false,\n sanitize: true\n }\n })\n markdown;\n }\n ```\n\n ```js [app/transforms/markdown.js]\n export default class MarkdownTransform {\n serialize(deserialized, options) {\n return deserialized.raw;\n }\n\n deserialize(serialized, options) {\n let markdownOptions = options.markdown || {};\n\n return marked(serialized, markdownOptions);\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @class Transform\n @public\n */\nexport const Transform: typeof EmberObject = EmberObject;\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface BooleanTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'boolean';\n}\n\n/**\n The `BooleanTransform` class is used to serialize and deserialize\n boolean attributes on Ember Data record objects. This transform is\n used when `'boolean'` is passed as the type parameter to the\n {@link attr}function.\n\n Usage\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('boolean') isAdmin;\n @attr('string') name;\n @attr('string') email;\n }\n ```\n\n By default, the boolean transform only allows for values of `true` or\n `false`. You can opt into allowing `null` values for\n boolean attributes via `attr('boolean', { allowNull: true })`\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') email;\n @attr('string') username;\n @attr('boolean', { allowNull: true }) wantsWeeklyEmail;\n }\n ```\n\n @public\n */\nexport class BooleanTransform {\n /**\n * Converts a serialized (raw payload) value into a `boolean` (or `null`\n * when `allowNull` is set and the value is nullish).\n */\n deserialize(serialized: boolean | null | number | string, options?: { allowNull?: boolean }): boolean | null {\n if ((serialized === null || serialized === undefined) && options?.allowNull === true) {\n return null;\n }\n\n if (typeof serialized === 'boolean') {\n return serialized;\n } else if (typeof serialized === 'string') {\n return /^(true|t|1)$/i.test(serialized);\n } else if (typeof serialized === 'number') {\n return serialized === 1;\n } else {\n return false;\n }\n }\n\n /**\n * Converts a `boolean` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: boolean | null, options?: { allowNull?: boolean }): boolean | null {\n if ((deserialized === null || deserialized === undefined) && options?.allowNull === true) {\n return null;\n }\n\n return Boolean(deserialized);\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): BooleanTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface DateTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'date';\n}\n/**\n The `DateTransform` class is used to serialize and deserialize\n date attributes on Ember Data record objects. This transform is used\n when `'date'` is passed as the type parameter to the\n {@link attr} function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)\n standard.\n\n ```js [app/models/score.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class ScoreModel extends Model {\n @attr('number') value;\n @belongsTo('player') player;\n @attr('date') date;\n }\n ```\n\n @public\n */\n\nexport class DateTransform {\n /**\n * Converts a serialized (raw payload) `ISO 8601` string, epoch number,\n * or nullish value into a `Date` (or `null`/`undefined`).\n */\n deserialize(serialized: string | number | null, _options?: Record<string, unknown>): Date | null {\n if (typeof serialized === 'string') {\n let offset = serialized.indexOf('+');\n\n if (offset !== -1 && serialized.length - 5 === offset) {\n offset += 3;\n return new Date(serialized.slice(0, offset) + ':' + serialized.slice(offset));\n }\n return new Date(serialized);\n } else if (typeof serialized === 'number') {\n return new Date(serialized);\n } else if (serialized === null || serialized === undefined) {\n // if the value is null return null\n // if the value is not present in the data return undefined\n return serialized;\n } else {\n return null;\n }\n }\n\n /**\n * Converts a `Date` attribute value into an `ISO 8601` string, or `null`\n * if the value is not a valid `Date`.\n */\n serialize(date: Date, _options?: Record<string, unknown>): string | null {\n // @ts-expect-error isNaN accepts date as it is coercible\n if (date instanceof Date && !isNaN(date)) {\n return date.toISOString();\n } else {\n return null;\n }\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): DateTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nfunction isNumber(value: number) {\n return value === value && value !== Infinity && value !== -Infinity;\n}\n\nexport interface NumberTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'number';\n}\n\n/**\n The `NumberTransform` class is used to serialize and deserialize\n numeric attributes on Ember Data record objects. This transform is\n used when `number` is passed as the type parameter to the\n {@link attr} function.\n\n Usage\n\n ```js [app/models/score.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class ScoreModel extends Model {\n @attr('number') value;\n @belongsTo('player') player;\n @attr('date') date;\n }\n ```\n\n @public\n */\nexport class NumberTransform {\n /**\n * Converts a serialized (raw payload) value into a `number`, or `null`\n * if the value is empty, nullish, or not a valid number.\n */\n deserialize(serialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null {\n if (serialized === '' || serialized === null || serialized === undefined) {\n return null;\n } else {\n const transformed = Number(serialized);\n\n return isNumber(transformed) ? transformed : null;\n }\n }\n\n /**\n * Converts a `number` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null {\n if (deserialized === '' || deserialized === null || deserialized === undefined) {\n return null;\n } else {\n const transformed = Number(deserialized);\n\n return isNumber(transformed) ? transformed : null;\n }\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): NumberTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface StringTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'string';\n}\n/**\n The `StringTransform` class is used to serialize and deserialize\n string attributes on Ember Data record objects. This transform is\n used when `string` is passed as the type parameter to the\n {@link attr} function.\n\n Usage\n\n ```js [app/models/user.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('boolean') isAdmin;\n @attr('string') name;\n @attr('string') email;\n }\n ```\n\n @public\n */\nexport class StringTransform {\n /**\n * Converts a serialized (raw payload) value into a `string`, or `null`\n * if the value is falsy (and not an empty string).\n */\n deserialize(serialized: unknown, _options?: Record<string, unknown>): string | null {\n return !serialized && serialized !== '' ? null : String(serialized);\n }\n /**\n * Converts a `string` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: unknown, _options?: Record<string, unknown>): string | null {\n return !deserialized && deserialized !== '' ? null : String(deserialized);\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): StringTransform {\n return new this();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyHA,MAAaC,YAAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3E7C,IAAaE,mBAAb,MAA8B;;;;;CAK5BC,YAAYC,YAA8CC,SAAmD;EAC3G,KAAKD,eAAe,QAAQA,eAAeE,WAAcD,SAASE,cAAc,MAC9E,OAAO;EAGT,IAAI,OAAOH,eAAe,WACxB,OAAOA;OACF,IAAI,OAAOA,eAAe,UAC/B,OAAO,gBAAgBI,KAAKJ,UAAU;OACjC,IAAI,OAAOA,eAAe,UAC/B,OAAOA,eAAe;OAEtB,OAAO;CAEX;;;;CAKAK,UAAUC,cAA8BL,SAAmD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B,MAAMA,iBAAiB,QAAQA,iBAAiBJ,QACnE,OAAO;OACF;GACL,MAAMC,cAAcC,OAAOE,YAAY;GAEvC,OAAOX,SAASQ,WAAW,IAAIA,cAAc;EAC/C;CACF;;;;CAKA,OAAOI,SAA0B;EAC/B,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;;;;;;;;;ACvCA,IAAaC,kBAAb,MAA6B;;;;;CAK3BC,YAAYC,YAAqBC,UAAmD;EAClF,OAAO,CAACD,cAAcA,eAAe,KAAK,OAAOE,OAAOF,UAAU;CACpE;;;;CAIAG,UAAUC,cAAuBH,UAAmD;EAClF,OAAO,CAACG,gBAAgBA,iBAAiB,KAAK,OAAOF,OAAOE,YAAY;CAC1E;;;;CAKA,OAAOC,SAA0B;EAC/B,OAAO,IAAI,KAAK;CAClB;AACF"}
|
|
1
|
+
{"version":3,"file":"transform.js","names":["EmberObject","Transform","BooleanTransform","deserialize","serialized","options","undefined","allowNull","test","serialize","deserialized","Boolean","create","DateTransform","deserialize","serialized","_options","offset","indexOf","length","Date","slice","undefined","serialize","date","isNaN","toISOString","create","isNumber","value","Infinity","NumberTransform","deserialize","serialized","_options","undefined","transformed","Number","serialize","deserialized","create","StringTransform","deserialize","serialized","_options","String","serialize","deserialized","create"],"sources":["../../../../src/serializer/-private/transforms/transform.ts","../../../../src/serializer/-private/transforms/boolean.ts","../../../../src/serializer/-private/transforms/date.ts","../../../../src/serializer/-private/transforms/number.ts","../../../../src/serializer/-private/transforms/string.ts"],"sourcesContent":["import EmberObject from '@ember/object';\n\nimport type { LegacyAttributeField } from '@warp-drive/core/types/schema/fields';\n\nexport interface Transform {\n /**\n When given a deserialized value from a record attribute this\n method must return the serialized value.\n\n Example\n\n ```javascript\n serialize(deserialized, options) {\n return deserialized ? null : Number(deserialized);\n }\n ```\n\n @public\n @param deserialized The deserialized value\n @param options hash of options passed to `attr`\n @return The serialized value\n */\n serialize(value: unknown, options: LegacyAttributeField['options']): unknown;\n\n /**\n When given a serialized value from a JSON object this method must\n return the deserialized value for the record attribute.\n\n Example\n\n ```javascript\n deserialize(serialized, options) {\n return empty(serialized) ? null : Number(serialized);\n }\n ```\n\n @public\n @param serialized The serialized value\n @param options hash of options passed to `attr`\n @return The deserialized value\n */\n deserialize(value: unknown, options: LegacyAttributeField['options']): unknown;\n}\n\n/**\n The `Transform` class is used to serialize and deserialize model\n attributes when they are saved or loaded from an\n adapter. Subclassing `Transform` is useful for creating custom\n attributes. All subclasses of `Transform` must implement a\n `serialize` and a `deserialize` method.\n\n Example\n\n ```js [app/transforms/temperature.js]\n\n // Converts centigrade in the JSON to fahrenheit in the app\n export default class TemperatureTransform {\n deserialize(serialized, options) {\n return (serialized * 1.8) + 32;\n }\n\n serialize(deserialized, options) {\n return (deserialized - 32) / 1.8;\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n Usage\n\n ```js [app/models/requirement.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class RequirementModel extends Model {\n @attr('string') name;\n @attr('temperature') temperature;\n }\n ```\n\n The options passed into the `attr` function when the attribute is\n declared on the model is also available in the transform.\n\n ```js [app/models/post.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class PostModel extends Model {\n @attr('string') title;\n @attr('markdown', {\n markdown: {\n gfm: false,\n sanitize: true\n }\n })\n markdown;\n }\n ```\n\n ```js [app/transforms/markdown.js]\n export default class MarkdownTransform {\n serialize(deserialized, options) {\n return deserialized.raw;\n }\n\n deserialize(serialized, options) {\n let markdownOptions = options.markdown || {};\n\n return marked(serialized, markdownOptions);\n }\n\n static create() {\n return new this();\n }\n }\n ```\n\n @summary Legacy base for custom attribute transforms, which implement `serialize` and `deserialize` to convert\n values between payloads and records.\n @class Transform\n @public\n */\nexport const Transform: typeof EmberObject = EmberObject;\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface BooleanTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'boolean';\n}\n\n/**\n The `BooleanTransform` class is used to serialize and deserialize\n boolean attributes on Ember Data record objects. This transform is\n used when `'boolean'` is passed as the type parameter to the\n {@link attr}function.\n\n Usage\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('boolean') isAdmin;\n @attr('string') name;\n @attr('string') email;\n }\n ```\n\n By default, the boolean transform only allows for values of `true` or\n `false`. You can opt into allowing `null` values for\n boolean attributes via `attr('boolean', { allowNull: true })`\n\n ```js [app/models/user.js]\n import { Model, attr } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('string') email;\n @attr('string') username;\n @attr('boolean', { allowNull: true }) wantsWeeklyEmail;\n }\n ```\n\n @summary Legacy transform for `attr('boolean')` that converts payload values to and from booleans, optionally\n allowing `null`.\n @public\n */\nexport class BooleanTransform {\n /**\n * Converts a serialized (raw payload) value into a `boolean` (or `null`\n * when `allowNull` is set and the value is nullish).\n */\n deserialize(serialized: boolean | null | number | string, options?: { allowNull?: boolean }): boolean | null {\n if ((serialized === null || serialized === undefined) && options?.allowNull === true) {\n return null;\n }\n\n if (typeof serialized === 'boolean') {\n return serialized;\n } else if (typeof serialized === 'string') {\n return /^(true|t|1)$/i.test(serialized);\n } else if (typeof serialized === 'number') {\n return serialized === 1;\n } else {\n return false;\n }\n }\n\n /**\n * Converts a `boolean` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: boolean | null, options?: { allowNull?: boolean }): boolean | null {\n if ((deserialized === null || deserialized === undefined) && options?.allowNull === true) {\n return null;\n }\n\n return Boolean(deserialized);\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): BooleanTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface DateTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'date';\n}\n/**\n The `DateTransform` class is used to serialize and deserialize\n date attributes on Ember Data record objects. This transform is used\n when `'date'` is passed as the type parameter to the\n {@link attr} function. It uses the [`ISO 8601`](https://en.wikipedia.org/wiki/ISO_8601)\n standard.\n\n ```js [app/models/score.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class ScoreModel extends Model {\n @attr('number') value;\n @belongsTo('player') player;\n @attr('date') date;\n }\n ```\n\n @summary Legacy transform for `attr('date')` that converts ISO 8601 strings or epoch numbers to `Date` objects and\n serializes them back to ISO 8601 strings.\n @public\n */\n\nexport class DateTransform {\n /**\n * Converts a serialized (raw payload) `ISO 8601` string, epoch number,\n * or nullish value into a `Date` (or `null`/`undefined`).\n */\n deserialize(serialized: string | number | null, _options?: Record<string, unknown>): Date | null {\n if (typeof serialized === 'string') {\n let offset = serialized.indexOf('+');\n\n if (offset !== -1 && serialized.length - 5 === offset) {\n offset += 3;\n return new Date(serialized.slice(0, offset) + ':' + serialized.slice(offset));\n }\n return new Date(serialized);\n } else if (typeof serialized === 'number') {\n return new Date(serialized);\n } else if (serialized === null || serialized === undefined) {\n // if the value is null return null\n // if the value is not present in the data return undefined\n return serialized;\n } else {\n return null;\n }\n }\n\n /**\n * Converts a `Date` attribute value into an `ISO 8601` string, or `null`\n * if the value is not a valid `Date`.\n */\n serialize(date: Date, _options?: Record<string, unknown>): string | null {\n // @ts-expect-error isNaN accepts date as it is coercible\n if (date instanceof Date && !isNaN(date)) {\n return date.toISOString();\n } else {\n return null;\n }\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): DateTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nfunction isNumber(value: number) {\n return value === value && value !== Infinity && value !== -Infinity;\n}\n\nexport interface NumberTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'number';\n}\n\n/**\n The `NumberTransform` class is used to serialize and deserialize\n numeric attributes on Ember Data record objects. This transform is\n used when `number` is passed as the type parameter to the\n {@link attr} function.\n\n Usage\n\n ```js [app/models/score.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class ScoreModel extends Model {\n @attr('number') value;\n @belongsTo('player') player;\n @attr('date') date;\n }\n ```\n\n @summary Legacy transform for `attr('number')` that converts payload values to numbers, or `null` when empty or not\n a valid number.\n @public\n */\nexport class NumberTransform {\n /**\n * Converts a serialized (raw payload) value into a `number`, or `null`\n * if the value is empty, nullish, or not a valid number.\n */\n deserialize(serialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null {\n if (serialized === '' || serialized === null || serialized === undefined) {\n return null;\n } else {\n const transformed = Number(serialized);\n\n return isNumber(transformed) ? transformed : null;\n }\n }\n\n /**\n * Converts a `number` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: string | number | null | undefined, _options?: Record<string, unknown>): number | null {\n if (deserialized === '' || deserialized === null || deserialized === undefined) {\n return null;\n } else {\n const transformed = Number(deserialized);\n\n return isNumber(transformed) ? transformed : null;\n }\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): NumberTransform {\n return new this();\n }\n}\n","import type { TransformName } from '@warp-drive/core/types/symbols';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { attr } from '../../../model';\n\nexport interface StringTransform {\n /**\n * see {@link TransformName}\n */\n [TransformName]: 'string';\n}\n/**\n The `StringTransform` class is used to serialize and deserialize\n string attributes on Ember Data record objects. This transform is\n used when `string` is passed as the type parameter to the\n {@link attr} function.\n\n Usage\n\n ```js [app/models/user.js]\n import Model, { attr, belongsTo } from '@warp-drive/legacy/model';\n\n export default class UserModel extends Model {\n @attr('boolean') isAdmin;\n @attr('string') name;\n @attr('string') email;\n }\n ```\n\n @summary Legacy transform for `attr('string')` that converts payload values to and from strings.\n @public\n */\nexport class StringTransform {\n /**\n * Converts a serialized (raw payload) value into a `string`, or `null`\n * if the value is falsy (and not an empty string).\n */\n deserialize(serialized: unknown, _options?: Record<string, unknown>): string | null {\n return !serialized && serialized !== '' ? null : String(serialized);\n }\n /**\n * Converts a `string` attribute value into its serialized (raw payload) form.\n */\n serialize(deserialized: unknown, _options?: Record<string, unknown>): string | null {\n return !deserialized && deserialized !== '' ? null : String(deserialized);\n }\n\n /**\n * Creates a new instance of this transform.\n */\n static create(): StringTransform {\n return new this();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2HA,MAAaC,YAAgCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC3E7C,IAAaE,mBAAb,MAA8B;;;;;CAK5BC,YAAYC,YAA8CC,SAAmD;EAC3G,KAAKD,eAAe,QAAQA,eAAeE,WAAcD,SAASE,cAAc,MAC9E,OAAO;EAGT,IAAI,OAAOH,eAAe,WACxB,OAAOA;OACF,IAAI,OAAOA,eAAe,UAC/B,OAAO,gBAAgBI,KAAKJ,UAAU;OACjC,IAAI,OAAOA,eAAe,UAC/B,OAAOA,eAAe;OAEtB,OAAO;CAEX;;;;CAKAK,UAAUC,cAA8BL,SAAmD;EACzF,KAAKK,iBAAiB,QAAQA,iBAAiBJ,WAAcD,SAASE,cAAc,MAClF,OAAO;EAGT,OAAOI,QAAQD,YAAY;CAC7B;;;;CAKA,OAAOE,SAA2B;EAChC,OAAO,IAAI,KAAK;CAClB;AACF;;;;;;;;;;;;;;;;;;;;;;;;ACrDA,IAAaC,gBAAb,MAA2B;;;;;CAKzBC,YAAYC,YAAoCC,UAAiD;EAC/F,IAAI,OAAOD,eAAe,UAAU;GAClC,IAAIE,SAASF,WAAWG,QAAQ,GAAG;GAEnC,IAAID,WAAW,MAAMF,WAAWI,SAAS,MAAMF,QAAQ;IACrDA,UAAU;IACV,uBAAO,IAAIG,KAAKL,WAAWM,MAAM,GAAGJ,MAAM,IAAI,MAAMF,WAAWM,MAAMJ,MAAM,CAAC;GAC9E;GACA,OAAO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;CAClB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime--fcdnjmJ-
|
|
1
|
+
import { r as initializeDeferredDecorator, t as decorateFieldV2 } from "./runtime--fcdnjmJ-5yaSpa-d.js";
|
|
2
2
|
import EmberObject from "@ember/object";
|
|
3
3
|
import * as s from "@ember/service";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// src/serializer.ts
|
|
6
6
|
/**
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
@@ -23,6 +23,42 @@ Data received from an API response is **normalized** into
|
|
|
23
23
|
by WarpDrive), while data sent to an API is **serialized**
|
|
24
24
|
into the format the API expects.
|
|
25
25
|
|
|
26
|
+
### Why It's Legacy
|
|
27
|
+
|
|
28
|
+
The Serializer pattern was designed to transform data between your API's format and the
|
|
29
|
+
{json:api} format the legacy store works with:
|
|
30
|
+
|
|
31
|
+
- `store.serializerFor` resolves a serializer by resource type at runtime, looking up
|
|
32
|
+
`serializer:<type>` and then `serializer:application` through Ember's owner, though an
|
|
33
|
+
API's format more often varies per API version than per resource type (see Serializer
|
|
34
|
+
Resolution below).
|
|
35
|
+
- Every response is converted into {json:api} before it reaches the cache, whatever format
|
|
36
|
+
the API actually uses.
|
|
37
|
+
- The provided serializer classes extend `EmberObject`, which, together with the owner
|
|
38
|
+
lookup, ties the pattern to Ember.
|
|
39
|
+
|
|
40
|
+
### Modern Alternative
|
|
41
|
+
|
|
42
|
+
Use [Handlers](/api/@warp-drive/core/request/types/Handler) with the {@link RequestManager}.
|
|
43
|
+
Modern ***Warp*Drive**:
|
|
44
|
+
|
|
45
|
+
- normalizes a payload inside a handler when it needs transforming, using plain functions
|
|
46
|
+
and helpers such as `dasherize` and `singularize` from `@warp-drive/utilities/string`
|
|
47
|
+
- lets you pick a cache that understands your API's format natively, such as `JSONAPICache`
|
|
48
|
+
from `@warp-drive/json-api` for {json:api}, or write your own that implements the Cache
|
|
49
|
+
interface
|
|
50
|
+
|
|
51
|
+
For an alternative modern pattern to Serializers, see the
|
|
52
|
+
[Request Handlers Guide](/guides/the-manual/requests/handlers).
|
|
53
|
+
|
|
54
|
+
### Setup
|
|
55
|
+
|
|
56
|
+
Serializers run inside the `LegacyNetworkHandler` from
|
|
57
|
+
[`@warp-drive/legacy/compat`](/api/@warp-drive/legacy/compat/). A store created with
|
|
58
|
+
`useLegacyStore` adds it unless `linksMode` is `true`; a store you build yourself must add it
|
|
59
|
+
to its `RequestManager`, as shown in
|
|
60
|
+
[Configure the Store](/guides/configuration/legacy-package-setup/setup/universal.md#configure-the-store).
|
|
61
|
+
|
|
26
62
|
### Implementing a Serializer
|
|
27
63
|
|
|
28
64
|
There are only two required serializer methods, one for
|
|
@@ -106,6 +142,8 @@ by these serializers.
|
|
|
106
142
|
It is recommended that apps write their own serializer to best suit the needs of their API and
|
|
107
143
|
application.
|
|
108
144
|
|
|
145
|
+
@summary Legacy serializer layer that converts data between an API's format and JSON:API for the adapter-based
|
|
146
|
+
request flow.
|
|
109
147
|
@module
|
|
110
148
|
*/
|
|
111
149
|
const service = s.service ?? s.inject;
|
|
@@ -126,6 +164,8 @@ And you can optionally override the following methods:
|
|
|
126
164
|
|
|
127
165
|
For an example implementation, see the included {@link JSONSerializer}.
|
|
128
166
|
|
|
167
|
+
@summary Legacy abstract base class for serializers that normalize API responses into JSON:API and serialize
|
|
168
|
+
records into the API's request format.
|
|
129
169
|
@class Serializer
|
|
130
170
|
@public
|
|
131
171
|
*/
|
|
@@ -240,6 +280,5 @@ var Serializer = class extends EmberObject {
|
|
|
240
280
|
}
|
|
241
281
|
};
|
|
242
282
|
|
|
243
|
-
//#endregion
|
|
244
283
|
export { Serializer };
|
|
245
284
|
//# sourceMappingURL=serializer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","names":["EmberObject","s","g","i","service","inject","Serializer","prototype","store","normalize","_typeClass","hash"],"sources":["../../../src/serializer.ts"],"sourcesContent":["/**\n ## Overview\n\n :::danger\n ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.\n If starting a new app or thinking of implementing a new serializer, consider writing a\n {@link Handler} instead to be used with the {@link RequestManager}\n :::\n\n In order to properly manage and present your data, WarpDrive\n needs to understand the structure of data it receives.\n\n `Serializers` convert data between the server's API format and\n the format WarpDrive understands.\n\n Data received from an API response is **normalized** into\n [{json:api}](https://jsonapi.org/) (the format used internally\n by WarpDrive), while data sent to an API is **serialized**\n into the format the API expects.\n\n ### Implementing a Serializer\n\n There are only two required serializer methods, one for\n normalizing data from the server API format into {json:api}, and\n another for serializing records via `Snapshots` into the expected\n server API format.\n\n To implement a serializer, export a class that conforms to the structure\n described by {@link MinimumSerializerInterface}\n from the `app/serializers/` directory. An example is below.\n\n ```ts\n import EmberObject from '@ember/object';\n\n export default class ApplicationSerializer extends EmberObject {\n normalizeResponse(store, schema, rawPayload) {\n return rawPayload;\n }\n\n serialize(snapshot, options) {\n const serializedResource = {\n id: snapshot.id,\n type: snapshot.modelName,\n attributes: snapshot.attributes()\n };\n\n return serializedResource;\n }\n }\n ```\n\n\n ### Serializer Resolution\n\n `store.serializerFor(name)` will lookup serializers defined in\n `app/serializers/` and return an instance. If no serializer is found, an\n error will be thrown.\n\n `serializerFor` first attempts to find a serializer with an exact match on `name`,\n then falls back to checking for the presence of a serializer named `application`.\n\n ```ts\n store.serializerFor('author');\n\n // lookup paths (in order) =>\n // app/serializers/author.js\n // app/serializers/application.js\n ```\n\n Most requests in `@warp-drive/legacy` are made with respect to a particular `type` (or `modelName`)\n (e.g., \"get me the full collection of **books**\" or \"get me the **employee** whose id is 37\"). We\n refer to this as the **primary** resource `type`.\n\n Typically `serializerFor` will be used to find a serializer with a name matching that of the primary\n resource `type` for the request, falling back to the `application` serializer for those types that\n do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy\n for defining serializers. However, because APIs rarely format payloads per-type but rather\n per-API-version, this may not be a desired strategy.\n\n It is recommended that applications define only a single `application` adapter and serializer\n where possible.\n\n If you have multiple API formats and the per-type strategy is not viable, one strategy is to\n write an `application` adapter and serializer that make use of `options` to specify the desired\n format when making a request.\n\n ### Using a Serializer\n\n Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.\n\n ### Default Serializers\n\n For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**\n format the `@warp-drive/legacy/serializer` package contains implementations these applications can\n extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.\n\n Many applications will find writing their own serializer to be more performant and less\n complex than extending these classes even when their API format is very close to that expected\n by these serializers.\n\n It is recommended that apps write their own serializer to best suit the needs of their API and\n application.\n\n @module\n*/\nimport EmberObject from '@ember/object';\nimport * as s from '@ember/service';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { RequestManager, Store } from '@warp-drive/core';\n// oxlint-disable-next-line no-unused-vars\nimport type { Handler } from '@warp-drive/core/request';\nimport type { ModelSchema } from '@warp-drive/core/types';\nimport type { EmptyResourceDocument, SingleResourceDocument } from '@warp-drive/core/types/spec/json-api-raw';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { MinimumSerializerInterface } from './compat';\n// oxlint-disable-next-line no-unused-vars\nimport type { JSONSerializer } from './serializer/json';\n\nconst service = s.service ?? s.inject;\n\n/**\n > ⚠️ CAUTION you likely want the docs for {@link MinimumSerializerInterface}\n > as extending this abstract class is unnecessary.\n\n `Serializer` is an abstract base class that you may override in your\n application to customize it for your backend. The minimum set of methods\n that you should implement is:\n\n * `normalizeResponse()`\n * `serialize()`\n\n And you can optionally override the following methods:\n\n * `normalize()`\n\n For an example implementation, see the included {@link JSONSerializer}.\n\n @class Serializer\n @public\n*/\n\nexport class Serializer extends EmberObject {\n /**\n The `store` property is the application's `store` that contains\n all records. It can be used to look up serializers for other model\n types that may be nested inside the payload response.\n\n Example:\n\n ```js\n Serializer.extend({\n extractRelationship(relationshipModelName, relationshipHash) {\n let modelClass = this.store.modelFor(relationshipModelName);\n let relationshipSerializer = this.store.serializerFor(relationshipModelName);\n return relationshipSerializer.normalize(modelClass, relationshipHash);\n }\n });\n ```\n\n @public\n */\n @service declare store: Store;\n\n /**\n The `normalizeResponse` method is used to normalize a payload from the\n server to a JSON-API Document.\n\n http://jsonapi.org/format/#document-structure\n\n Example:\n\n ```js\n Serializer.extend({\n normalizeResponse(store, primaryModelClass, payload, id, requestType) {\n if (requestType === 'findRecord') {\n return this.normalize(primaryModelClass, payload);\n } else {\n return payload.reduce(function(documentHash, item) {\n let { data, included } = this.normalize(primaryModelClass, item);\n documentHash.included.push(...included);\n documentHash.data.push(data);\n return documentHash;\n }, { data: [], included: [] })\n }\n }\n });\n ```\n\n @since 1.13.0\n @public\n @param {Store} store\n @param {Model} primaryModelClass\n @param {Object} payload\n @param {String|Number} id\n @param {String} requestType\n @return {Object} JSON-API Document\n */\n\n /**\n The `serialize` method is used when a record is saved in order to convert\n the record into the form that your external data source expects.\n\n `serialize` takes an optional `options` hash with a single option:\n\n - `includeId`: If this is `true`, `serialize` should include the ID\n in the serialized object it builds.\n\n Example:\n\n ```js\n Serializer.extend({\n serialize(snapshot, options) {\n let json = {\n id: snapshot.id\n };\n\n snapshot.eachAttribute((key, attribute) => {\n json[key] = snapshot.attr(key);\n });\n\n snapshot.eachRelationship((key, relationship) => {\n if (relationship.kind === 'belongsTo') {\n json[key] = snapshot.belongsTo(key, { id: true });\n } else if (relationship.kind === 'hasMany') {\n json[key] = snapshot.hasMany(key, { ids: true });\n }\n });\n\n return json;\n },\n });\n ```\n\n @public\n @param {Snapshot} snapshot\n @param {Object} [options]\n @return {Object}\n */\n\n /**\n The `normalize` method is used to convert a payload received from your\n external data source into the normalized form `store.push()` expects. You\n should override this method, munge the hash and return the normalized\n payload.\n\n Example:\n\n ```js\n Serializer.extend({\n normalize(modelClass, resourceHash) {\n let data = {\n id: resourceHash.id,\n type: modelClass.modelName,\n attributes: resourceHash\n };\n return { data: data };\n }\n })\n ```\n\n @public\n @param _typeClass - the model class the hash is being normalized for\n @param hash - the raw payload hash to normalize\n @return the normalized resource document\n */\n normalize(_typeClass: ModelSchema, hash: Record<string, unknown>): SingleResourceDocument | EmptyResourceDocument {\n return hash as unknown as SingleResourceDocument;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHA,MAAMI,UAAUH,EAAEG,WAAWH,EAAEI;;;;;;;;;;;;;;;;;;;;;AAuB/B,IAAaC,aAAb,cAAgCN,YAAY;CAAA;EAAAE,gBAAA,KAAAK,WAAA,SAAA,CAoBzCH,OAAO,CAAA;CAAA;CAAA,UAAAD,4BAAA,MAAA,OAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwGRM,UAAUC,YAAyBC,MAA+E;EAChH,OAAOA;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"serializer.js","names":["EmberObject","s","g","i","service","inject","Serializer","prototype","store","normalize","_typeClass","hash","i"],"sources":["../../../src/serializer.ts"],"sourcesContent":["/**\n ## Overview\n\n :::danger\n ⚠️ **This is LEGACY documentation** for a feature that is no longer encouraged to be used.\n If starting a new app or thinking of implementing a new serializer, consider writing a\n {@link Handler} instead to be used with the {@link RequestManager}\n :::\n\n In order to properly manage and present your data, WarpDrive\n needs to understand the structure of data it receives.\n\n `Serializers` convert data between the server's API format and\n the format WarpDrive understands.\n\n Data received from an API response is **normalized** into\n [{json:api}](https://jsonapi.org/) (the format used internally\n by WarpDrive), while data sent to an API is **serialized**\n into the format the API expects.\n\n ### Why It's Legacy\n\n The Serializer pattern was designed to transform data between your API's format and the\n {json:api} format the legacy store works with:\n\n - `store.serializerFor` resolves a serializer by resource type at runtime, looking up\n `serializer:<type>` and then `serializer:application` through Ember's owner, though an\n API's format more often varies per API version than per resource type (see Serializer\n Resolution below).\n - Every response is converted into {json:api} before it reaches the cache, whatever format\n the API actually uses.\n - The provided serializer classes extend `EmberObject`, which, together with the owner\n lookup, ties the pattern to Ember.\n\n ### Modern Alternative\n\n Use [Handlers](/api/@warp-drive/core/request/types/Handler) with the {@link RequestManager}.\n Modern ***Warp*Drive**:\n\n - normalizes a payload inside a handler when it needs transforming, using plain functions\n and helpers such as `dasherize` and `singularize` from `@warp-drive/utilities/string`\n - lets you pick a cache that understands your API's format natively, such as `JSONAPICache`\n from `@warp-drive/json-api` for {json:api}, or write your own that implements the Cache\n interface\n\n For an alternative modern pattern to Serializers, see the\n [Request Handlers Guide](/guides/the-manual/requests/handlers).\n\n ### Setup\n\n Serializers run inside the `LegacyNetworkHandler` from\n [`@warp-drive/legacy/compat`](/api/@warp-drive/legacy/compat/). A store created with\n `useLegacyStore` adds it unless `linksMode` is `true`; a store you build yourself must add it\n to its `RequestManager`, as shown in\n [Configure the Store](/guides/configuration/legacy-package-setup/setup/universal.md#configure-the-store).\n\n ### Implementing a Serializer\n\n There are only two required serializer methods, one for\n normalizing data from the server API format into {json:api}, and\n another for serializing records via `Snapshots` into the expected\n server API format.\n\n To implement a serializer, export a class that conforms to the structure\n described by {@link MinimumSerializerInterface}\n from the `app/serializers/` directory. An example is below.\n\n ```ts\n import EmberObject from '@ember/object';\n\n export default class ApplicationSerializer extends EmberObject {\n normalizeResponse(store, schema, rawPayload) {\n return rawPayload;\n }\n\n serialize(snapshot, options) {\n const serializedResource = {\n id: snapshot.id,\n type: snapshot.modelName,\n attributes: snapshot.attributes()\n };\n\n return serializedResource;\n }\n }\n ```\n\n\n ### Serializer Resolution\n\n `store.serializerFor(name)` will lookup serializers defined in\n `app/serializers/` and return an instance. If no serializer is found, an\n error will be thrown.\n\n `serializerFor` first attempts to find a serializer with an exact match on `name`,\n then falls back to checking for the presence of a serializer named `application`.\n\n ```ts\n store.serializerFor('author');\n\n // lookup paths (in order) =>\n // app/serializers/author.js\n // app/serializers/application.js\n ```\n\n Most requests in `@warp-drive/legacy` are made with respect to a particular `type` (or `modelName`)\n (e.g., \"get me the full collection of **books**\" or \"get me the **employee** whose id is 37\"). We\n refer to this as the **primary** resource `type`.\n\n Typically `serializerFor` will be used to find a serializer with a name matching that of the primary\n resource `type` for the request, falling back to the `application` serializer for those types that\n do not have a defined serializer. This is often described as a `per-model` or `per-type` strategy\n for defining serializers. However, because APIs rarely format payloads per-type but rather\n per-API-version, this may not be a desired strategy.\n\n It is recommended that applications define only a single `application` adapter and serializer\n where possible.\n\n If you have multiple API formats and the per-type strategy is not viable, one strategy is to\n write an `application` adapter and serializer that make use of `options` to specify the desired\n format when making a request.\n\n ### Using a Serializer\n\n Any serializer in `app/serializers/` can be looked up by `name` using `store.serializerFor(name)`.\n\n ### Default Serializers\n\n For applications whose APIs are *very close to* or *exactly* the **REST** format or **JSON:API**\n format the `@warp-drive/legacy/serializer` package contains implementations these applications can\n extend. It also contains a simple `JSONSerializer` for serializing to/from very basic JSON objects.\n\n Many applications will find writing their own serializer to be more performant and less\n complex than extending these classes even when their API format is very close to that expected\n by these serializers.\n\n It is recommended that apps write their own serializer to best suit the needs of their API and\n application.\n\n @summary Legacy serializer layer that converts data between an API's format and JSON:API for the adapter-based\n request flow.\n @module\n*/\nimport EmberObject from '@ember/object';\nimport * as s from '@ember/service';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { RequestManager, Store } from '@warp-drive/core';\n// oxlint-disable-next-line no-unused-vars\nimport type { Handler } from '@warp-drive/core/request';\nimport type { ModelSchema } from '@warp-drive/core/types';\nimport type { EmptyResourceDocument, SingleResourceDocument } from '@warp-drive/core/types/spec/json-api-raw';\n\n// oxlint-disable-next-line no-unused-vars\nimport type { MinimumSerializerInterface } from './compat';\n// oxlint-disable-next-line no-unused-vars\nimport type { JSONSerializer } from './serializer/json';\n\nconst service = s.service ?? s.inject;\n\n/**\n > ⚠️ CAUTION you likely want the docs for {@link MinimumSerializerInterface}\n > as extending this abstract class is unnecessary.\n\n `Serializer` is an abstract base class that you may override in your\n application to customize it for your backend. The minimum set of methods\n that you should implement is:\n\n * `normalizeResponse()`\n * `serialize()`\n\n And you can optionally override the following methods:\n\n * `normalize()`\n\n For an example implementation, see the included {@link JSONSerializer}.\n\n @summary Legacy abstract base class for serializers that normalize API responses into JSON:API and serialize\n records into the API's request format.\n @class Serializer\n @public\n*/\n\nexport class Serializer extends EmberObject {\n /**\n The `store` property is the application's `store` that contains\n all records. It can be used to look up serializers for other model\n types that may be nested inside the payload response.\n\n Example:\n\n ```js\n Serializer.extend({\n extractRelationship(relationshipModelName, relationshipHash) {\n let modelClass = this.store.modelFor(relationshipModelName);\n let relationshipSerializer = this.store.serializerFor(relationshipModelName);\n return relationshipSerializer.normalize(modelClass, relationshipHash);\n }\n });\n ```\n\n @public\n */\n @service declare store: Store;\n\n /**\n The `normalizeResponse` method is used to normalize a payload from the\n server to a JSON-API Document.\n\n http://jsonapi.org/format/#document-structure\n\n Example:\n\n ```js\n Serializer.extend({\n normalizeResponse(store, primaryModelClass, payload, id, requestType) {\n if (requestType === 'findRecord') {\n return this.normalize(primaryModelClass, payload);\n } else {\n return payload.reduce(function(documentHash, item) {\n let { data, included } = this.normalize(primaryModelClass, item);\n documentHash.included.push(...included);\n documentHash.data.push(data);\n return documentHash;\n }, { data: [], included: [] })\n }\n }\n });\n ```\n\n @since 1.13.0\n @public\n @param {Store} store\n @param {Model} primaryModelClass\n @param {Object} payload\n @param {String|Number} id\n @param {String} requestType\n @return {Object} JSON-API Document\n */\n\n /**\n The `serialize` method is used when a record is saved in order to convert\n the record into the form that your external data source expects.\n\n `serialize` takes an optional `options` hash with a single option:\n\n - `includeId`: If this is `true`, `serialize` should include the ID\n in the serialized object it builds.\n\n Example:\n\n ```js\n Serializer.extend({\n serialize(snapshot, options) {\n let json = {\n id: snapshot.id\n };\n\n snapshot.eachAttribute((key, attribute) => {\n json[key] = snapshot.attr(key);\n });\n\n snapshot.eachRelationship((key, relationship) => {\n if (relationship.kind === 'belongsTo') {\n json[key] = snapshot.belongsTo(key, { id: true });\n } else if (relationship.kind === 'hasMany') {\n json[key] = snapshot.hasMany(key, { ids: true });\n }\n });\n\n return json;\n },\n });\n ```\n\n @public\n @param {Snapshot} snapshot\n @param {Object} [options]\n @return {Object}\n */\n\n /**\n The `normalize` method is used to convert a payload received from your\n external data source into the normalized form `store.push()` expects. You\n should override this method, munge the hash and return the normalized\n payload.\n\n Example:\n\n ```js\n Serializer.extend({\n normalize(modelClass, resourceHash) {\n let data = {\n id: resourceHash.id,\n type: modelClass.modelName,\n attributes: resourceHash\n };\n return { data: data };\n }\n })\n ```\n\n @public\n @param _typeClass - the model class the hash is being normalized for\n @param hash - the raw payload hash to normalize\n @return the normalized resource document\n */\n normalize(_typeClass: ModelSchema, hash: Record<string, unknown>): SingleResourceDocument | EmptyResourceDocument {\n return hash as unknown as SingleResourceDocument;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,MAAMI,UAAUH,EAAEG,WAAWH,EAAEI;;;;;;;;;;;;;;;;;;;;;;;AAyB/B,IAAaC,aAAb,cAAgCN,YAAY;CAAA;EAAAE,gBAAA,KAAAK,WAAA,SAAA,CAoBzCH,OAAO,CAAA;CAAA;CAAA,UAAAD,4BAAA,MAAA,OAAA,GAAA,KAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwGRM,UAAUC,YAAyBC,MAA+E;EAChH,OAAOA;CACT;AACF"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { n as normalizeModelName } from "./util-
|
|
2
|
-
import { t as isMaybeIdentifier } from "./utils-
|
|
1
|
+
import { n as normalizeModelName } from "./util-CI7b4vAE.js";
|
|
2
|
+
import { t as isMaybeIdentifier } from "./utils-_O0MjUTU.js";
|
|
3
3
|
import { assertPrivateStore, constructResource, ensureStringId, recordIdentifierFor } from "@warp-drive/core/store/-private";
|
|
4
4
|
import { getOrSetGlobal } from "@warp-drive/core/types/-private";
|
|
5
5
|
import { defineSignal } from "@warp-drive/core/signals/-leaked";
|
|
6
6
|
import { SkipCache } from "@warp-drive/core/types/request";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// src/store/-private.ts
|
|
9
9
|
function preloadData(store, identifier, preload) {
|
|
10
10
|
const jsonPayload = {};
|
|
11
11
|
const fields = store.schema.fields(identifier);
|
|
@@ -269,14 +269,21 @@ var ShimModelClass = class {
|
|
|
269
269
|
}
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
// src/store.ts
|
|
273
|
+
/**
|
|
274
|
+
* @module
|
|
275
|
+
* @summary Legacy `restoreDeprecatedStoreBehaviors`, which restores the adapter-based `findRecord`, `findAll`, `query`,
|
|
276
|
+
* `saveRecord` and related methods onto a `Store` class.
|
|
277
|
+
*/
|
|
274
278
|
/**
|
|
275
279
|
* Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/
|
|
276
280
|
* `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`
|
|
277
281
|
* legacy-network-layer implementations of these methods onto the given
|
|
278
282
|
* `Store` subclass, for apps that have not yet migrated to the
|
|
279
283
|
* `RequestManager`-based equivalents.
|
|
284
|
+
*
|
|
285
|
+
* @summary Legacy opt-in that restores the adapter-based `findRecord`, `findAll`, `query`, `saveRecord`, and related
|
|
286
|
+
* methods onto a `Store` class.
|
|
280
287
|
*/
|
|
281
288
|
function restoreDeprecatedStoreBehaviors(StoreKlass) {
|
|
282
289
|
StoreKlass.prototype.findRecord = function(resource, id, options) {
|
|
@@ -387,6 +394,5 @@ function upgradeInstanceCaches(cache) {
|
|
|
387
394
|
return withReferences;
|
|
388
395
|
}
|
|
389
396
|
|
|
390
|
-
//#endregion
|
|
391
397
|
export { restoreDeprecatedStoreBehaviors as t };
|
|
392
|
-
//# sourceMappingURL=store-
|
|
398
|
+
//# sourceMappingURL=store-BsSkzWgk.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-0L2CkYzh.js","names":["defineSignal","assertPrivateStore","ensureStringId","recordIdentifierFor","getOrSetGlobal","preloadData","store","identifier","preload","jsonPayload","schemas","schema","fields","Object","keys","forEach","key","preloadValue","field","get","kind","relationships","preloadRelationship","attributes","cache","hasRecord","Boolean","_instanceCache","peek","upsert","relatedType","type","data","map","value","_convertPreloadRelationshipToJSON","id","_resourceIsFullDeleted","isDeletionCommitted","isNew","isDeleted","resourceIsFullyDeleted","instanceCache","RecordReference","___token","___identifier","constructor","notifications","subscribe","_","bucket","notifiedKey","_ref","destroy","unsubscribe","remoteType","push","objectOrPromise","Promise","resolve","then","peekRecord","load","findRecord","reload","prototype","AvailableShims","WeakMap","getShimClass","modelName","shims","create","set","shim","undefined","ShimModelClass","__store","Map","fieldSchemas","attrs","relationshipsByName","rels","eachAttribute","callback","binding","call","eachRelationship","eachTransformedAttribute","assertPrivateStore","constructResource","ensureStringId","recordIdentifierFor","storeFor","SkipCache","isMaybeIdentifier","normalizeModelName","getShimClass","preloadData","RecordReference","resourceIsFullyDeleted","restoreDeprecatedStoreBehaviors","StoreKlass","prototype","findRecord","resource","id","options","type","normalizedId","identifier","cacheKeyManager","getOrCreateRecordIdentifier","preload","_instanceCache","recordIsLoaded","reload","_join","promise","request","op","data","record","cacheOptions","then","document","content","findAll","query","queryRecord","getReference","resourceIdentifier","arguments","length","cache","upgradeInstanceCaches","__instances","reference","get","set","modelFor","saveRecord","Promise","reject","Error","resolve","operation","isNew","isDeleted","records","withReferences","WeakMap"],"sources":["../../../src/store/-private.ts","../../../src/store.ts"],"sourcesContent":["import type { NotificationType } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { defineSignal } from '@warp-drive/core/signals/-leaked';\nimport {\n assertPrivateStore,\n ensureStringId,\n type InstanceCache,\n recordIdentifierFor,\n} from '@warp-drive/core/store/-private';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { NewResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n LegacyAttributeField,\n LegacyRelationshipField,\n LegacyRelationshipField as RelationshipSchema,\n} from '@warp-drive/core/types/schema/fields';\nimport type {\n ExistingResourceIdentifierObject,\n ExistingResourceObject,\n InnerRelationshipDocument,\n SingleResourceDocument,\n} from '@warp-drive/core/types/spec/json-api-raw';\n\nimport type { Store } from '../store.ts';\n\n/*\n When a find request is triggered on the store, the user can optionally pass in\n attributes and relationships to be preloaded. These are meant to behave as if they\n came back from the server, except the user obtained them out of band and is informing\n the store of their existence. The most common use case is for supporting client side\n nested URLs, such as `/posts/1/comments/2` so the user can do\n `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.\n\n Preloaded data can be attributes and relationships passed in either as IDs or as actual\n models.\n */\ntype PreloadRelationshipValue = OpaqueRecordInstance | string;\nexport function preloadData(store: Store, identifier: NewResourceKey, preload: Record<string, Value>): void {\n const jsonPayload: Partial<ExistingResourceObject> = {};\n //TODO(Igor) consider the polymorphic case\n const schemas = store.schema;\n const fields = schemas.fields(identifier);\n Object.keys(preload).forEach((key) => {\n const preloadValue = preload[key];\n\n const field = fields.get(key);\n if (field && (field.kind === 'hasMany' || field.kind === 'belongsTo')) {\n if (!jsonPayload.relationships) {\n jsonPayload.relationships = {};\n }\n jsonPayload.relationships[key] = preloadRelationship(field, preloadValue);\n } else {\n if (!jsonPayload.attributes) {\n jsonPayload.attributes = {};\n }\n jsonPayload.attributes[key] = preloadValue;\n }\n });\n const cache = store.cache;\n assertPrivateStore(store);\n const hasRecord = Boolean(store._instanceCache.peek(identifier));\n cache.upsert(identifier, jsonPayload, hasRecord);\n}\n\nfunction preloadRelationship(\n schema: RelationshipSchema,\n preloadValue: PreloadRelationshipValue | null | Array<PreloadRelationshipValue>\n): InnerRelationshipDocument<ExistingResourceIdentifierObject> {\n const relatedType = schema.type;\n\n if (schema.kind === 'hasMany') {\n assert('You need to pass in an array to set a hasMany property on a record', Array.isArray(preloadValue));\n return { data: preloadValue.map((value) => _convertPreloadRelationshipToJSON(value, relatedType)) };\n }\n\n assert('You should not pass in an array to set a belongsTo property on a record', !Array.isArray(preloadValue));\n return { data: preloadValue ? _convertPreloadRelationshipToJSON(preloadValue, relatedType) : null };\n}\n\n/*\n findRecord('user', '1', { preload: { friends: ['1'] }});\n findRecord('user', '1', { preload: { friends: [record] }});\n*/\nfunction _convertPreloadRelationshipToJSON(\n value: OpaqueRecordInstance | string,\n type: string\n): ExistingResourceIdentifierObject {\n if (typeof value === 'string' || typeof value === 'number') {\n return { type, id: ensureStringId(value) };\n }\n // TODO if not a record instance assert it's an identifier\n // and allow identifiers to be used\n return recordIdentifierFor(value) as ExistingResourceIdentifierObject;\n}\n\nexport interface BaseFinderOptions {\n reload?: boolean;\n backgroundReload?: boolean;\n include?: string | string[];\n adapterOptions?: Record<string, unknown>;\n}\nexport interface FindRecordOptions extends BaseFinderOptions {\n /**\n * Data to preload into the store before the request is made.\n * This feature is *highly* discouraged and has no corresponding\n * feature when using builders and handlers.\n *\n * Excepting relationships: the data should be in the form of a\n * JSON object where the keys are fields on the record and the value\n * is the raw value to be added to the cache.\n *\n * Relationships can either be provided as string IDs from which\n * an identifier will be built base upon the relationship's expected\n * resource type, or be record instances from which the identifier\n * will be extracted.\n *\n */\n preload?: Record<string, Value>;\n}\n\nexport type QueryOptions = {\n [K in string | 'adapterOptions']?: K extends 'adapterOptions' ? Record<string, unknown> : unknown;\n};\n\nexport type FindAllOptions = BaseFinderOptions;\nexport type LegacyResourceQuery = {\n include?: string | string[];\n [key: string]: Value | undefined;\n};\n\nexport type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;\n\n/**\n * Minimum subset of static schema methods and properties on the\n * \"model\" class.\n *\n * Only used when using the legacy schema-service implementation\n * for @ember-data/model or when wrapping schema for legacy\n * Adapters/Serializers.\n *\n */\nexport interface ModelSchema<T = unknown> {\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n fields: Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>;\n attributes: Map<KeyOrString<T>, LegacyAttributeField>;\n relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;\n eachAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void;\n eachRelationship<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void;\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, type: string | null) => void,\n binding?: T\n ): void;\n}\n\nfunction _resourceIsFullDeleted(identifier: ResourceKey, cache: Cache): boolean {\n return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));\n}\n\nexport function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: ResourceKey): boolean {\n const cache = instanceCache.cache;\n return !cache || _resourceIsFullDeleted(identifier, cache);\n}\n\n/**\n A `RecordReference` is a low-level API that allows users and\n addon authors to perform meta-operations on a record.\n\n @hideconstructor\n @public\n*/\nexport class RecordReference {\n /** @internal */\n declare private store: Store;\n // unsubscribe token given to us by the notification manager\n /** @internal */\n private ___token!: object;\n /** @internal */\n private ___identifier: ResourceKey;\n /** @internal */\n declare private _ref: number;\n\n constructor(store: Store, identifier: ResourceKey) {\n this.store = store;\n this.___identifier = identifier;\n this.___token = store.notifications.subscribe(\n identifier,\n (_: ResourceKey, bucket: NotificationType, notifiedKey?: string) => {\n if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {\n this._ref++;\n }\n }\n );\n }\n\n /** @internal */\n destroy(): void {\n this.store.notifications.unsubscribe(this.___token);\n }\n\n get type(): string {\n return this.identifier().type;\n }\n\n /**\n The `id` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.id(); // '1'\n ```\n\n @public\n @return The id of the record.\n */\n id(): string | null {\n // oxlint-disable-next-line no-unused-expressions\n this._ref; // consume the tracked prop\n return this.___identifier.id;\n }\n\n /**\n The `identifier` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.identifier(); // '1'\n ```\n\n @public\n @return The identifier of the record.\n */\n identifier(): ResourceKey {\n return this.___identifier;\n }\n\n /**\n How the reference will be looked up when it is loaded. Currently\n this always returns `identity` to signify that a record will be\n loaded by its `type` and `id`.\n\n Example\n\n ```javascript\n const userRef = store.getReference('user', 1);\n\n userRef.remoteType(); // 'identity'\n ```\n\n @public\n */\n remoteType(): 'identity' {\n return 'identity';\n }\n\n /**\n This API allows you to provide a reference with new data. The\n simplest usage of this API is similar to `store.push`: you provide a\n normalized hash of data and the object represented by the reference\n will update.\n\n If you pass a promise to `push`, WarpDrive will not ask the adapter\n for the data if another attempt to fetch it is made in the\n interim. When the promise resolves, the underlying object is updated\n with the new data, and the promise returned by *this function* is resolved\n with that object.\n\n For example, `recordReference.push(promise)` will be resolved with a\n record.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // provide data for reference\n userRef.push({\n data: {\n id: \"1\",\n type: \"user\",\n attributes: {\n username: \"@user\"\n }\n }\n }).then(function(user) {\n userRef.value() === user;\n });\n ```\n\n @public\n @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one\n @return a promise for the value (record or relationship)\n */\n push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance> {\n // TODO @deprecate pushing unresolved payloads\n return Promise.resolve(objectOrPromise).then((data) => {\n return this.store.push(data);\n });\n }\n\n /**\n If the entity referred to by the reference is already loaded, it is\n present as `reference.value`. Otherwise the value returned by this function\n is `null`.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.value(); // user\n ```\n\n @public\n @return the record for this RecordReference\n */\n value(): OpaqueRecordInstance | null {\n return this.store.peekRecord(this.___identifier);\n }\n\n /**\n Triggers a fetch for the backing entity based on its `remoteType`\n (see `remoteType` definitions per reference type).\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // load user (via store.find)\n userRef.load().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n load(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id);\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n\n /**\n Reloads the record if it is already loaded. If the record is not\n loaded it will load the record via `store.findRecord`\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // or trigger a reload\n userRef.reload().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n reload(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id, { reload: true });\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n}\n\ndefineSignal(RecordReference.prototype, '_ref');\n\n// if modelFor turns out to be a bottleneck we should replace with a Map\n// and clear it during store teardown.\nconst AvailableShims = getOrSetGlobal('AvailableShims', new WeakMap<Store, Record<string, ShimModelClass>>());\n\nexport function getShimClass<T>(\n store: Store,\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n): ShimModelClass<T> {\n let shims = AvailableShims.get(store);\n\n if (!shims) {\n shims = Object.create(null) as Record<string, ShimModelClass>;\n AvailableShims.set(store, shims);\n }\n\n let shim = shims[modelName];\n if (shim === undefined) {\n shim = shims[modelName] = new ShimModelClass<unknown>(store, modelName);\n }\n\n return shim;\n}\n\n// Mimics the static apis of @ember-data/model\nexport class ShimModelClass<T = unknown> implements ModelSchema<T> {\n declare __store: Store;\n declare modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string) {\n this.__store = store;\n this.modelName = modelName;\n }\n\n get fields(): Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'> {\n const fields = new Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>();\n const fieldSchemas = this.__store.schema.fields({ type: this.modelName });\n\n fieldSchemas.forEach((schema, key) => {\n if (schema.kind === 'attribute' || schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n fields.set(key as KeyOrString<T>, schema.kind);\n }\n });\n\n return fields;\n }\n\n get attributes(): Map<KeyOrString<T>, LegacyAttributeField> {\n const attrs = new Map<KeyOrString<T>, LegacyAttributeField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n attrs.set(key as KeyOrString<T>, schema);\n }\n });\n\n return attrs;\n }\n\n get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField> {\n const rels = new Map<KeyOrString<T>, LegacyRelationshipField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n rels.set(key as KeyOrString<T>, schema);\n }\n });\n\n return rels;\n }\n\n eachAttribute<K extends KeyOrString<T>>(\n callback: (key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachRelationship<K extends KeyOrString<T>>(\n callback: (key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (key: K, type: string | null) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n const type = schema.type;\n if (type) callback.call(binding, key as K, type);\n }\n });\n }\n}\n","import type { Store } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { LegacyLiveArray, LegacyQueryArray, PrivateStore } from '@warp-drive/core/store/-private';\nimport {\n assertPrivateStore,\n constructResource,\n ensureStringId,\n recordIdentifierFor,\n storeFor,\n} from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport { SkipCache } from '@warp-drive/core/types/request';\nimport type { ResourceIdentifierObject } from '@warp-drive/core/types/spec/json-api-raw';\n\nimport { isMaybeIdentifier } from './compat/builders/utils.ts';\nimport { normalizeModelName } from './model/-private/util.ts';\nimport type {\n FindAllOptions,\n FindRecordOptions,\n LegacyResourceQuery,\n ModelSchema,\n QueryOptions,\n} from './store/-private.ts';\nimport { getShimClass, preloadData, RecordReference, resourceIsFullyDeleted } from './store/-private.ts';\n\n/**\n * Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/\n * `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`\n * legacy-network-layer implementations of these methods onto the given\n * `Store` subclass, for apps that have not yet migrated to the\n * `RequestManager`-based equivalents.\n */\nexport function restoreDeprecatedStoreBehaviors(StoreKlass: typeof Store): void {\n StoreKlass.prototype.findRecord = function (\n resource: string | ResourceIdentifierObject,\n id?: string | number | FindRecordOptions,\n options?: FindRecordOptions\n ): Promise<unknown> {\n assert(\n `Attempted to call store.findRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`,\n resource\n );\n if (isMaybeIdentifier(resource)) {\n options = id as FindRecordOptions;\n } else {\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`,\n typeof resource === 'string'\n );\n const type = normalizeModelName(resource);\n const normalizedId = ensureStringId(id as string | number);\n resource = constructResource(type, normalizedId);\n }\n\n const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resource);\n options = options || {};\n assertPrivateStore(this);\n\n if (options.preload) {\n // force reload if we preload to ensure we don't resolve the promise\n // until we are complete, else we will end up background-reloading\n // even for initial load.\n if (!this._instanceCache.recordIsLoaded(identifier)) {\n options.reload = true;\n }\n this._join(() => {\n preloadData(this, identifier, options.preload!);\n });\n }\n\n const promise = this.request<OpaqueRecordInstance>({\n op: 'findRecord',\n data: {\n record: identifier,\n options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => {\n return document.content;\n });\n };\n\n StoreKlass.prototype.findAll = function <T>(\n type: TypeFromInstance<T> | string,\n options: FindAllOptions = {}\n ): Promise<LegacyLiveArray<T>> {\n assert(\n `Attempted to call store.findAll(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's findAll method`, type);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyLiveArray<T>>({\n op: 'findAll',\n data: {\n type: normalizeModelName(type),\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.query = function (\n type: string,\n query: LegacyResourceQuery,\n options: QueryOptions = {}\n ): Promise<LegacyQueryArray> {\n assert(\n `Attempted to call store.query(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's query method`, type);\n assert(`You need to pass a query hash to the store's query method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyQueryArray>({\n op: 'query',\n data: {\n type: normalizeModelName(type),\n query,\n options: options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.queryRecord = function (\n type: string,\n query: Record<string, unknown>,\n options?: QueryOptions\n ): Promise<OpaqueRecordInstance | null> {\n assert(\n `Attempted to call store.queryRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's queryRecord method`, type);\n assert(`You need to pass a query hash to the store's queryRecord method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<OpaqueRecordInstance | null>({\n op: 'queryRecord',\n data: {\n type: normalizeModelName(type),\n query,\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n // do not put a ts-expect-error here, because typedoc will fail to\n // build due to this error only occurring when references are in use in the editor.\n // The return statement below casts to `PrivateStore['getReference']`'s return\n // type rather than annotating this function `: RecordReference` directly,\n // since this package's `RecordReference` and core's `deprecated/-private.ts`\n // copy are structurally identical but nominally distinct classes (TS treats\n // their private fields as separate brands); casting only the return value\n // (instead of the whole function) keeps `this` contextually typed from the\n // assignment target below.\n StoreKlass.prototype.getReference = function (resource: string | ResourceIdentifierObject, id: string | number) {\n assert(\n `Attempted to call store.getReference(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n let resourceIdentifier: ResourceIdentifierObject;\n if (arguments.length === 1 && isMaybeIdentifier(resource)) {\n resourceIdentifier = resource;\n } else {\n const type = normalizeModelName(resource as string);\n const normalizedId = ensureStringId(id);\n resourceIdentifier = constructResource(type, normalizedId);\n }\n\n assert(\n 'getReference expected to receive either a resource identifier or type and id as arguments',\n isMaybeIdentifier(resourceIdentifier)\n );\n\n const identifier: ResourceKey = this.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);\n assertPrivateStore(this);\n\n const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;\n let reference = cache.get(identifier);\n\n if (!reference) {\n reference = new RecordReference(this, identifier);\n cache.set(identifier, reference);\n }\n return reference;\n };\n\n StoreKlass.prototype.modelFor = function <T>(\n type: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n ): ModelSchema<T> {\n assert(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`, !this.isDestroyed);\n assert(`You need to pass <type> to the store's modelFor method`, typeof type === 'string' && type.length);\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n\n return getShimClass<T>(this, type);\n };\n\n StoreKlass.prototype.saveRecord = function <T>(record: T, options: Record<string, unknown> = {}): Promise<T> {\n assert(\n `Attempted to call store.saveRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`Unable to initiate save for a record in a disconnected state`, storeFor(record, true));\n const identifier = recordIdentifierFor(record);\n const cache = this.cache;\n\n if (!identifier) {\n // this commonly means we're disconnected\n // but just in case we reject here to prevent bad things.\n return Promise.reject(new Error(`Record Is Disconnected`));\n }\n assertPrivateStore(this);\n assert(\n `Cannot initiate a save request for an unloaded record: ${identifier.lid}`,\n this._instanceCache.recordIsLoaded(identifier)\n );\n if (resourceIsFullyDeleted(this._instanceCache, identifier)) {\n return Promise.resolve(record);\n }\n\n if (!options) {\n options = {};\n }\n let operation: 'createRecord' | 'deleteRecord' | 'updateRecord' = 'updateRecord';\n\n if (cache.isNew(identifier)) {\n operation = 'createRecord';\n } else if (cache.isDeleted(identifier)) {\n operation = 'deleteRecord';\n }\n\n const request = {\n op: operation,\n data: {\n options,\n record: identifier,\n },\n records: [identifier],\n cacheOptions: { [SkipCache]: true },\n };\n\n return this.request<T>(request).then((document) => document.content);\n };\n}\n\nexport type { Store };\n\ntype Caches = PrivateStore['_instanceCache']['__instances'];\nfunction upgradeInstanceCaches(cache: Caches): Caches & { reference: WeakMap<ResourceKey, RecordReference> } {\n const withReferences = cache as Caches & { reference: WeakMap<ResourceKey, RecordReference> };\n if (!withReferences.reference) {\n withReferences.reference = new WeakMap();\n }\n\n return withReferences;\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgBK,YAAYC,OAAcC,YAA4BC,SAAsC;CAC1G,MAAMC,cAA+C,CAAC;CAGtD,MAAMG,SADUN,MAAMK,OACCC,OAAOL,UAAU;CACxCM,OAAOC,KAAKN,OAAO,CAAC,CAACO,SAASC,QAAQ;EACpC,MAAMC,eAAeT,QAAQQ;EAE7B,MAAME,QAAQN,OAAOO,IAAIH,GAAG;EAC5B,IAAIE,UAAUA,MAAME,SAAS,aAAaF,MAAME,SAAS,cAAc;GACrE,IAAI,CAACX,YAAYY,eACfZ,YAAYY,gBAAgB,CAAC;GAE/BZ,YAAYY,cAAcL,OAAOM,oBAAoBJ,OAAOD,YAAY;EAC1E,OAAO;GACL,IAAI,CAACR,YAAYc,YACfd,YAAYc,aAAa,CAAC;GAE5Bd,YAAYc,WAAWP,OAAOC;EAChC;CACF,CAAC;CACD,MAAMO,QAAQlB,MAAMkB;CACpBvB,mBAAmBK,KAAK;CACxB,MAAMmB,YAAYC,QAAQpB,MAAMqB,eAAeC,KAAKrB,UAAU,CAAC;CAC/DiB,MAAMK,OAAOtB,YAAYE,aAAagB,SAAS;AACjD;AAEA,SAASH,oBACPX,QACAM,cAC6D;CAC7D,MAAMa,cAAcnB,OAAOoB;CAE3B,IAAIpB,OAAOS,SAAS,WAElB,OAAO,EAAEY,MAAMf,aAAagB,KAAKC,UAAUC,kCAAkCD,OAAOJ,WAAW,CAAC,EAAE;CAIpG,OAAO,EAAEE,MAAMf,eAAekB,kCAAkClB,cAAca,WAAW,IAAI,KAAK;AACpG;AAMA,SAASK,kCACPD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gC,QAAQC,uBAAO,IAAIC,MAAM,wBAAwB,CAAC;EAE3DvD,mBAAmB,IAAI;EAKvB,IAAIW,uBAAuB,KAAKc,gBAAgBJ,UAAU,GACxD,OAAOgC,QAAQG,QAAQvB,MAAM;EAG/B,IAAI,CAACf,SACHA,UAAU,CAAC;EAEb,IAAIuC,YAA8D;EAElE,IAAIZ,MAAMa,MAAMrC,UAAU,GACxBoC,YAAY;OACP,IAAIZ,MAAMc,UAAUtC,UAAU,GACnCoC,YAAY;EAGd,MAAM3B,UAAU;GACdC,IAAI0B;GACJzB,MAAM;IACJd;IACAe,QAAQZ;GACV;GACAuC,SAAS,CAACvC,UAAU;GACpBa,cAAc,GAAG7B,YAAY,KAAK;EACpC;EAEA,OAAO,KAAKyB,QAAWA,OAAO,CAAC,CAACK,MAAMC,aAAaA,SAASC,OAAO;CACrE;AACF;AAKA,SAASS,sBAAsBD,OAA8E;CAC3G,MAAMgB,iBAAiBhB;CACvB,IAAI,CAACgB,eAAeb,WAClBa,eAAeb,4BAAY,IAAIc,QAAQ;CAGzC,OAAOD;AACT"}
|
|
1
|
+
{"version":3,"file":"store-BsSkzWgk.js","names":["defineSignal","assertPrivateStore","ensureStringId","recordIdentifierFor","getOrSetGlobal","preloadData","store","identifier","preload","jsonPayload","schemas","schema","fields","Object","keys","forEach","key","preloadValue","field","get","kind","relationships","preloadRelationship","attributes","cache","hasRecord","Boolean","_instanceCache","peek","upsert","relatedType","type","data","map","value","_convertPreloadRelationshipToJSON","id","_resourceIsFullDeleted","isDeletionCommitted","isNew","isDeleted","resourceIsFullyDeleted","instanceCache","RecordReference","___token","___identifier","constructor","notifications","subscribe","_","bucket","notifiedKey","_ref","destroy","unsubscribe","remoteType","push","objectOrPromise","Promise","resolve","then","peekRecord","load","findRecord","reload","prototype","AvailableShims","WeakMap","getShimClass","modelName","shims","create","set","shim","undefined","ShimModelClass","__store","Map","fieldSchemas","attrs","relationshipsByName","rels","eachAttribute","callback","binding","call","eachRelationship","eachTransformedAttribute","assertPrivateStore","constructResource","ensureStringId","recordIdentifierFor","storeFor","SkipCache","isMaybeIdentifier","normalizeModelName","getShimClass","preloadData","RecordReference","resourceIsFullyDeleted","restoreDeprecatedStoreBehaviors","StoreKlass","prototype","findRecord","resource","id","options","type","normalizedId","identifier","cacheKeyManager","getOrCreateRecordIdentifier","preload","_instanceCache","recordIsLoaded","reload","_join","promise","request","op","data","record","cacheOptions","then","document","content","findAll","query","queryRecord","getReference","resourceIdentifier","arguments","length","cache","upgradeInstanceCaches","__instances","reference","get","set","modelFor","saveRecord","Promise","reject","Error","resolve","operation","isNew","isDeleted","records","withReferences","WeakMap"],"sources":["../../../src/store/-private.ts","../../../src/store.ts"],"sourcesContent":["import type { NotificationType } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { defineSignal } from '@warp-drive/core/signals/-leaked';\nimport {\n assertPrivateStore,\n ensureStringId,\n type InstanceCache,\n recordIdentifierFor,\n} from '@warp-drive/core/store/-private';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { Cache } from '@warp-drive/core/types/cache';\nimport type { NewResourceKey, ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { Value } from '@warp-drive/core/types/json/raw';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport type {\n LegacyAttributeField,\n LegacyRelationshipField,\n LegacyRelationshipField as RelationshipSchema,\n} from '@warp-drive/core/types/schema/fields';\nimport type {\n ExistingResourceIdentifierObject,\n ExistingResourceObject,\n InnerRelationshipDocument,\n SingleResourceDocument,\n} from '@warp-drive/core/types/spec/json-api-raw';\n\nimport type { Store } from '../store.ts';\n\n/*\n When a find request is triggered on the store, the user can optionally pass in\n attributes and relationships to be preloaded. These are meant to behave as if they\n came back from the server, except the user obtained them out of band and is informing\n the store of their existence. The most common use case is for supporting client side\n nested URLs, such as `/posts/1/comments/2` so the user can do\n `store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.\n\n Preloaded data can be attributes and relationships passed in either as IDs or as actual\n models.\n */\ntype PreloadRelationshipValue = OpaqueRecordInstance | string;\nexport function preloadData(store: Store, identifier: NewResourceKey, preload: Record<string, Value>): void {\n const jsonPayload: Partial<ExistingResourceObject> = {};\n //TODO(Igor) consider the polymorphic case\n const schemas = store.schema;\n const fields = schemas.fields(identifier);\n Object.keys(preload).forEach((key) => {\n const preloadValue = preload[key];\n\n const field = fields.get(key);\n if (field && (field.kind === 'hasMany' || field.kind === 'belongsTo')) {\n if (!jsonPayload.relationships) {\n jsonPayload.relationships = {};\n }\n jsonPayload.relationships[key] = preloadRelationship(field, preloadValue);\n } else {\n if (!jsonPayload.attributes) {\n jsonPayload.attributes = {};\n }\n jsonPayload.attributes[key] = preloadValue;\n }\n });\n const cache = store.cache;\n assertPrivateStore(store);\n const hasRecord = Boolean(store._instanceCache.peek(identifier));\n cache.upsert(identifier, jsonPayload, hasRecord);\n}\n\nfunction preloadRelationship(\n schema: RelationshipSchema,\n preloadValue: PreloadRelationshipValue | null | Array<PreloadRelationshipValue>\n): InnerRelationshipDocument<ExistingResourceIdentifierObject> {\n const relatedType = schema.type;\n\n if (schema.kind === 'hasMany') {\n assert('You need to pass in an array to set a hasMany property on a record', Array.isArray(preloadValue));\n return { data: preloadValue.map((value) => _convertPreloadRelationshipToJSON(value, relatedType)) };\n }\n\n assert('You should not pass in an array to set a belongsTo property on a record', !Array.isArray(preloadValue));\n return { data: preloadValue ? _convertPreloadRelationshipToJSON(preloadValue, relatedType) : null };\n}\n\n/*\n findRecord('user', '1', { preload: { friends: ['1'] }});\n findRecord('user', '1', { preload: { friends: [record] }});\n*/\nfunction _convertPreloadRelationshipToJSON(\n value: OpaqueRecordInstance | string,\n type: string\n): ExistingResourceIdentifierObject {\n if (typeof value === 'string' || typeof value === 'number') {\n return { type, id: ensureStringId(value) };\n }\n // TODO if not a record instance assert it's an identifier\n // and allow identifiers to be used\n return recordIdentifierFor(value) as ExistingResourceIdentifierObject;\n}\n\nexport interface BaseFinderOptions {\n reload?: boolean;\n backgroundReload?: boolean;\n include?: string | string[];\n adapterOptions?: Record<string, unknown>;\n}\nexport interface FindRecordOptions extends BaseFinderOptions {\n /**\n * Data to preload into the store before the request is made.\n * This feature is *highly* discouraged and has no corresponding\n * feature when using builders and handlers.\n *\n * Excepting relationships: the data should be in the form of a\n * JSON object where the keys are fields on the record and the value\n * is the raw value to be added to the cache.\n *\n * Relationships can either be provided as string IDs from which\n * an identifier will be built base upon the relationship's expected\n * resource type, or be record instances from which the identifier\n * will be extracted.\n *\n */\n preload?: Record<string, Value>;\n}\n\nexport type QueryOptions = {\n [K in string | 'adapterOptions']?: K extends 'adapterOptions' ? Record<string, unknown> : unknown;\n};\n\nexport type FindAllOptions = BaseFinderOptions;\nexport type LegacyResourceQuery = {\n include?: string | string[];\n [key: string]: Value | undefined;\n};\n\nexport type KeyOrString<T> = keyof T & string extends never ? string : keyof T & string;\n\n/**\n * Minimum subset of static schema methods and properties on the\n * \"model\" class.\n *\n * Only used when using the legacy schema-service implementation\n * for @ember-data/model or when wrapping schema for legacy\n * Adapters/Serializers.\n *\n */\nexport interface ModelSchema<T = unknown> {\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n fields: Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>;\n attributes: Map<KeyOrString<T>, LegacyAttributeField>;\n relationshipsByName: Map<KeyOrString<T>, LegacyRelationshipField>;\n eachAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void;\n eachRelationship<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void;\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (this: ModelSchema<T>, key: K, type: string | null) => void,\n binding?: T\n ): void;\n}\n\nfunction _resourceIsFullDeleted(identifier: ResourceKey, cache: Cache): boolean {\n return cache.isDeletionCommitted(identifier) || (cache.isNew(identifier) && cache.isDeleted(identifier));\n}\n\nexport function resourceIsFullyDeleted(instanceCache: InstanceCache, identifier: ResourceKey): boolean {\n const cache = instanceCache.cache;\n return !cache || _resourceIsFullDeleted(identifier, cache);\n}\n\n/**\n A `RecordReference` is a low-level API that allows users and\n addon authors to perform meta-operations on a record.\n\n @hideconstructor\n @public\n*/\nexport class RecordReference {\n /** @internal */\n declare private store: Store;\n // unsubscribe token given to us by the notification manager\n /** @internal */\n private ___token!: object;\n /** @internal */\n private ___identifier: ResourceKey;\n /** @internal */\n declare private _ref: number;\n\n constructor(store: Store, identifier: ResourceKey) {\n this.store = store;\n this.___identifier = identifier;\n this.___token = store.notifications.subscribe(\n identifier,\n (_: ResourceKey, bucket: NotificationType, notifiedKey?: string) => {\n if (bucket === 'identity' || (bucket === 'attributes' && notifiedKey === 'id')) {\n this._ref++;\n }\n }\n );\n }\n\n /** @internal */\n destroy(): void {\n this.store.notifications.unsubscribe(this.___token);\n }\n\n get type(): string {\n return this.identifier().type;\n }\n\n /**\n The `id` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.id(); // '1'\n ```\n\n @public\n @return The id of the record.\n */\n id(): string | null {\n // oxlint-disable-next-line no-unused-expressions\n this._ref; // consume the tracked prop\n return this.___identifier.id;\n }\n\n /**\n The `identifier` of the record that this reference refers to.\n\n Together, the `type` and `id` properties form a composite key for\n the identity map.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.identifier(); // '1'\n ```\n\n @public\n @return The identifier of the record.\n */\n identifier(): ResourceKey {\n return this.___identifier;\n }\n\n /**\n How the reference will be looked up when it is loaded. Currently\n this always returns `identity` to signify that a record will be\n loaded by its `type` and `id`.\n\n Example\n\n ```javascript\n const userRef = store.getReference('user', 1);\n\n userRef.remoteType(); // 'identity'\n ```\n\n @public\n */\n remoteType(): 'identity' {\n return 'identity';\n }\n\n /**\n This API allows you to provide a reference with new data. The\n simplest usage of this API is similar to `store.push`: you provide a\n normalized hash of data and the object represented by the reference\n will update.\n\n If you pass a promise to `push`, WarpDrive will not ask the adapter\n for the data if another attempt to fetch it is made in the\n interim. When the promise resolves, the underlying object is updated\n with the new data, and the promise returned by *this function* is resolved\n with that object.\n\n For example, `recordReference.push(promise)` will be resolved with a\n record.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // provide data for reference\n userRef.push({\n data: {\n id: \"1\",\n type: \"user\",\n attributes: {\n username: \"@user\"\n }\n }\n }).then(function(user) {\n userRef.value() === user;\n });\n ```\n\n @public\n @param objectOrPromise a JSON:API ResourceDocument or a promise resolving to one\n @return a promise for the value (record or relationship)\n */\n push(objectOrPromise: SingleResourceDocument | Promise<SingleResourceDocument>): Promise<OpaqueRecordInstance> {\n // TODO @deprecate pushing unresolved payloads\n return Promise.resolve(objectOrPromise).then((data) => {\n return this.store.push(data);\n });\n }\n\n /**\n If the entity referred to by the reference is already loaded, it is\n present as `reference.value`. Otherwise the value returned by this function\n is `null`.\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n userRef.value(); // user\n ```\n\n @public\n @return the record for this RecordReference\n */\n value(): OpaqueRecordInstance | null {\n return this.store.peekRecord(this.___identifier);\n }\n\n /**\n Triggers a fetch for the backing entity based on its `remoteType`\n (see `remoteType` definitions per reference type).\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // load user (via store.find)\n userRef.load().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n load(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id);\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n\n /**\n Reloads the record if it is already loaded. If the record is not\n loaded it will load the record via `store.findRecord`\n\n Example\n\n ```javascript\n let userRef = store.getReference('user', 1);\n\n // or trigger a reload\n userRef.reload().then(...)\n ```\n\n @public\n @return the record for this RecordReference\n */\n reload(): Promise<unknown> {\n const id = this.id();\n if (id !== null) {\n return this.store.findRecord(this.type, id, { reload: true });\n }\n assert(`Unable to fetch record of type ${this.type} without an id`);\n }\n}\n\ndefineSignal(RecordReference.prototype, '_ref');\n\n// if modelFor turns out to be a bottleneck we should replace with a Map\n// and clear it during store teardown.\nconst AvailableShims = getOrSetGlobal('AvailableShims', new WeakMap<Store, Record<string, ShimModelClass>>());\n\nexport function getShimClass<T>(\n store: Store,\n modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n): ShimModelClass<T> {\n let shims = AvailableShims.get(store);\n\n if (!shims) {\n shims = Object.create(null) as Record<string, ShimModelClass>;\n AvailableShims.set(store, shims);\n }\n\n let shim = shims[modelName];\n if (shim === undefined) {\n shim = shims[modelName] = new ShimModelClass<unknown>(store, modelName);\n }\n\n return shim;\n}\n\n// Mimics the static apis of @ember-data/model\nexport class ShimModelClass<T = unknown> implements ModelSchema<T> {\n declare __store: Store;\n declare modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string;\n constructor(store: Store, modelName: T extends TypedRecordInstance ? TypeFromInstance<T> : string) {\n this.__store = store;\n this.modelName = modelName;\n }\n\n get fields(): Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'> {\n const fields = new Map<KeyOrString<T>, 'attribute' | 'belongsTo' | 'hasMany'>();\n const fieldSchemas = this.__store.schema.fields({ type: this.modelName });\n\n fieldSchemas.forEach((schema, key) => {\n if (schema.kind === 'attribute' || schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n fields.set(key as KeyOrString<T>, schema.kind);\n }\n });\n\n return fields;\n }\n\n get attributes(): Map<KeyOrString<T>, LegacyAttributeField> {\n const attrs = new Map<KeyOrString<T>, LegacyAttributeField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n attrs.set(key as KeyOrString<T>, schema);\n }\n });\n\n return attrs;\n }\n\n get relationshipsByName(): Map<KeyOrString<T>, LegacyRelationshipField> {\n const rels = new Map<KeyOrString<T>, LegacyRelationshipField>();\n const fields = this.__store.schema.fields({ type: this.modelName });\n\n fields.forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n rels.set(key as KeyOrString<T>, schema);\n }\n });\n\n return rels;\n }\n\n eachAttribute<K extends KeyOrString<T>>(\n callback: (key: K, attribute: LegacyAttributeField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachRelationship<K extends KeyOrString<T>>(\n callback: (key: K, relationship: LegacyRelationshipField) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'belongsTo' || schema.kind === 'hasMany') {\n callback.call(binding, key as K, schema);\n }\n });\n }\n\n eachTransformedAttribute<K extends KeyOrString<T>>(\n callback: (key: K, type: string | null) => void,\n binding?: T\n ): void {\n this.__store.schema.fields({ type: this.modelName }).forEach((schema, key) => {\n if (schema.kind === 'attribute') {\n const type = schema.type;\n if (type) callback.call(binding, key as K, type);\n }\n });\n }\n}\n","/**\n * @module\n * @summary Legacy `restoreDeprecatedStoreBehaviors`, which restores the adapter-based `findRecord`, `findAll`, `query`,\n * `saveRecord` and related methods onto a `Store` class.\n */\n\nimport type { Store } from '@warp-drive/core';\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport type { LegacyLiveArray, LegacyQueryArray, PrivateStore } from '@warp-drive/core/store/-private';\nimport {\n assertPrivateStore,\n constructResource,\n ensureStringId,\n recordIdentifierFor,\n storeFor,\n} from '@warp-drive/core/store/-private';\nimport type { ResourceKey } from '@warp-drive/core/types/identifier';\nimport type { OpaqueRecordInstance, TypedRecordInstance, TypeFromInstance } from '@warp-drive/core/types/record';\nimport { SkipCache } from '@warp-drive/core/types/request';\nimport type { ResourceIdentifierObject } from '@warp-drive/core/types/spec/json-api-raw';\n\nimport { isMaybeIdentifier } from './compat/builders/utils.ts';\nimport { normalizeModelName } from './model/-private/util.ts';\nimport type {\n FindAllOptions,\n FindRecordOptions,\n LegacyResourceQuery,\n ModelSchema,\n QueryOptions,\n} from './store/-private.ts';\nimport { getShimClass, preloadData, RecordReference, resourceIsFullyDeleted } from './store/-private.ts';\n\n/**\n * Restores the deprecated `findRecord`/`findAll`/`query`/`queryRecord`/\n * `findBelongsTo`/`findHasMany`/`createRecord`/`deleteRecord`/`saveRecord`\n * legacy-network-layer implementations of these methods onto the given\n * `Store` subclass, for apps that have not yet migrated to the\n * `RequestManager`-based equivalents.\n *\n * @summary Legacy opt-in that restores the adapter-based `findRecord`, `findAll`, `query`, `saveRecord`, and related\n * methods onto a `Store` class.\n */\nexport function restoreDeprecatedStoreBehaviors(StoreKlass: typeof Store): void {\n StoreKlass.prototype.findRecord = function (\n resource: string | ResourceIdentifierObject,\n id?: string | number | FindRecordOptions,\n options?: FindRecordOptions\n ): Promise<unknown> {\n assert(\n `Attempted to call store.findRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n assert(\n `You need to pass a modelName or resource identifier as the first argument to the store's findRecord method`,\n resource\n );\n if (isMaybeIdentifier(resource)) {\n options = id as FindRecordOptions;\n } else {\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${resource}`,\n typeof resource === 'string'\n );\n const type = normalizeModelName(resource);\n const normalizedId = ensureStringId(id as string | number);\n resource = constructResource(type, normalizedId);\n }\n\n const identifier = this.cacheKeyManager.getOrCreateRecordIdentifier(resource);\n options = options || {};\n assertPrivateStore(this);\n\n if (options.preload) {\n // force reload if we preload to ensure we don't resolve the promise\n // until we are complete, else we will end up background-reloading\n // even for initial load.\n if (!this._instanceCache.recordIsLoaded(identifier)) {\n options.reload = true;\n }\n this._join(() => {\n preloadData(this, identifier, options.preload!);\n });\n }\n\n const promise = this.request<OpaqueRecordInstance>({\n op: 'findRecord',\n data: {\n record: identifier,\n options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => {\n return document.content;\n });\n };\n\n StoreKlass.prototype.findAll = function <T>(\n type: TypeFromInstance<T> | string,\n options: FindAllOptions = {}\n ): Promise<LegacyLiveArray<T>> {\n assert(\n `Attempted to call store.findAll(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's findAll method`, type);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyLiveArray<T>>({\n op: 'findAll',\n data: {\n type: normalizeModelName(type),\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.query = function (\n type: string,\n query: LegacyResourceQuery,\n options: QueryOptions = {}\n ): Promise<LegacyQueryArray> {\n assert(\n `Attempted to call store.query(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's query method`, type);\n assert(`You need to pass a query hash to the store's query method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<LegacyQueryArray>({\n op: 'query',\n data: {\n type: normalizeModelName(type),\n query,\n options: options,\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n StoreKlass.prototype.queryRecord = function (\n type: string,\n query: Record<string, unknown>,\n options?: QueryOptions\n ): Promise<OpaqueRecordInstance | null> {\n assert(\n `Attempted to call store.queryRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`You need to pass a model name to the store's queryRecord method`, type);\n assert(`You need to pass a query hash to the store's queryRecord method`, query);\n assert(\n `Passing classes to store methods has been removed. Please pass a dasherized string instead of ${type}`,\n typeof type === 'string'\n );\n\n const promise = this.request<OpaqueRecordInstance | null>({\n op: 'queryRecord',\n data: {\n type: normalizeModelName(type),\n query,\n options: options || {},\n },\n cacheOptions: { [SkipCache]: true },\n });\n\n return promise.then((document) => document.content);\n };\n\n // do not put a ts-expect-error here, because typedoc will fail to\n // build due to this error only occurring when references are in use in the editor.\n // The return statement below casts to `PrivateStore['getReference']`'s return\n // type rather than annotating this function `: RecordReference` directly,\n // since this package's `RecordReference` and core's `deprecated/-private.ts`\n // copy are structurally identical but nominally distinct classes (TS treats\n // their private fields as separate brands); casting only the return value\n // (instead of the whole function) keeps `this` contextually typed from the\n // assignment target below.\n StoreKlass.prototype.getReference = function (resource: string | ResourceIdentifierObject, id: string | number) {\n assert(\n `Attempted to call store.getReference(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n\n let resourceIdentifier: ResourceIdentifierObject;\n if (arguments.length === 1 && isMaybeIdentifier(resource)) {\n resourceIdentifier = resource;\n } else {\n const type = normalizeModelName(resource as string);\n const normalizedId = ensureStringId(id);\n resourceIdentifier = constructResource(type, normalizedId);\n }\n\n assert(\n 'getReference expected to receive either a resource identifier or type and id as arguments',\n isMaybeIdentifier(resourceIdentifier)\n );\n\n const identifier: ResourceKey = this.cacheKeyManager.getOrCreateRecordIdentifier(resourceIdentifier);\n assertPrivateStore(this);\n\n const cache = upgradeInstanceCaches(this._instanceCache.__instances).reference;\n let reference = cache.get(identifier);\n\n if (!reference) {\n reference = new RecordReference(this, identifier);\n cache.set(identifier, reference);\n }\n return reference;\n };\n\n StoreKlass.prototype.modelFor = function <T>(\n type: T extends TypedRecordInstance ? TypeFromInstance<T> : string\n ): ModelSchema<T> {\n assert(`Attempted to call store.modelFor(), but the store instance has already been destroyed.`, !this.isDestroyed);\n assert(`You need to pass <type> to the store's modelFor method`, typeof type === 'string' && type.length);\n assert(`No model was found for '${type}' and no schema handles the type`, this.schema.hasResource({ type }));\n\n return getShimClass<T>(this, type);\n };\n\n StoreKlass.prototype.saveRecord = function <T>(record: T, options: Record<string, unknown> = {}): Promise<T> {\n assert(\n `Attempted to call store.saveRecord(), but the store instance has already been destroyed.`,\n !(this.isDestroying || this.isDestroyed)\n );\n assert(`Unable to initiate save for a record in a disconnected state`, storeFor(record, true));\n const identifier = recordIdentifierFor(record);\n const cache = this.cache;\n\n if (!identifier) {\n // this commonly means we're disconnected\n // but just in case we reject here to prevent bad things.\n return Promise.reject(new Error(`Record Is Disconnected`));\n }\n assertPrivateStore(this);\n assert(\n `Cannot initiate a save request for an unloaded record: ${identifier.lid}`,\n this._instanceCache.recordIsLoaded(identifier)\n );\n if (resourceIsFullyDeleted(this._instanceCache, identifier)) {\n return Promise.resolve(record);\n }\n\n if (!options) {\n options = {};\n }\n let operation: 'createRecord' | 'deleteRecord' | 'updateRecord' = 'updateRecord';\n\n if (cache.isNew(identifier)) {\n operation = 'createRecord';\n } else if (cache.isDeleted(identifier)) {\n operation = 'deleteRecord';\n }\n\n const request = {\n op: operation,\n data: {\n options,\n record: identifier,\n },\n records: [identifier],\n cacheOptions: { [SkipCache]: true },\n };\n\n return this.request<T>(request).then((document) => document.content);\n };\n}\n\nexport type { Store };\n\ntype Caches = PrivateStore['_instanceCache']['__instances'];\nfunction upgradeInstanceCaches(cache: Caches): Caches & { reference: WeakMap<ResourceKey, RecordReference> } {\n const withReferences = cache as Caches & { reference: WeakMap<ResourceKey, RecordReference> };\n if (!withReferences.reference) {\n withReferences.reference = new WeakMap();\n }\n\n return withReferences;\n}\n"],"mappings":";;;;;;;;AAwCA,SAAgBK,YAAYC,OAAcC,YAA4BC,SAAsC;CAC1G,MAAMC,cAA+C,CAAC;CAGtD,MAAMG,SADUN,MAAMK,OACCC,OAAOL,UAAU;CACxCM,OAAOC,KAAKN,OAAO,CAAC,CAACO,SAASC,QAAQ;EACpC,MAAMC,eAAeT,QAAQQ;EAE7B,MAAME,QAAQN,OAAOO,IAAIH,GAAG;EAC5B,IAAIE,UAAUA,MAAME,SAAS,aAAaF,MAAME,SAAS,cAAc;GACrE,IAAI,CAACX,YAAYY,eACfZ,YAAYY,g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ACgB,eAAeb,WAClBa,eAAeb,4BAAY,IAAIc,QAAQ;CAGzC,OAAOD;AACT"}
|
package/dist/unpkg/prod/store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/model/-private/util.ts
|
|
2
2
|
function isElementDescriptor(args) {
|
|
3
3
|
const [maybeTarget, maybeKey, maybeDesc] = args;
|
|
4
4
|
return args.length === 3 && (typeof maybeTarget === "function" || typeof maybeTarget === "object" && maybeTarget !== null) && typeof maybeKey === "string" && (typeof maybeDesc === "object" && maybeDesc !== null && "enumerable" in maybeDesc && "configurable" in maybeDesc || maybeDesc === void 0);
|
|
@@ -7,6 +7,5 @@ function normalizeModelName(type) {
|
|
|
7
7
|
return type;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
//#endregion
|
|
11
10
|
export { normalizeModelName as n, isElementDescriptor as t };
|
|
12
|
-
//# sourceMappingURL=util-
|
|
11
|
+
//# sourceMappingURL=util-CI7b4vAE.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util-
|
|
1
|
+
{"version":3,"file":"util-CI7b4vAE.js","names":["dasherize","isElementDescriptor","args","maybeTarget","maybeKey","maybeDesc","length","undefined","normalizeModelName","type"],"sources":["../../../src/model/-private/util.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport { dasherize } from '@warp-drive/utilities/string';\n\nexport type DecoratorPropertyDescriptor = (PropertyDescriptor & { initializer?: () => unknown }) | undefined;\n\nexport function isElementDescriptor(args: unknown[]): args is [object, string, DecoratorPropertyDescriptor] {\n const [maybeTarget, maybeKey, maybeDesc] = args;\n\n return (\n // Ensure we have the right number of args\n args.length === 3 &&\n // Make sure the target is a class or object (prototype)\n (typeof maybeTarget === 'function' || (typeof maybeTarget === 'object' && maybeTarget !== null)) &&\n // Make sure the key is a string\n typeof maybeKey === 'string' &&\n // Make sure the descriptor is the right shape\n ((typeof maybeDesc === 'object' &&\n maybeDesc !== null &&\n 'enumerable' in maybeDesc &&\n 'configurable' in maybeDesc) ||\n // TS compatibility\n maybeDesc === undefined)\n );\n}\n\nexport function normalizeModelName(type: string): string {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = dasherize(type);\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n"],"mappings":";AAOA,SAAgBC,oBAAoBC,MAAwE;CAC1G,MAAM,CAACC,aAAaC,UAAUC,aAAaH;CAE3C,OAEEA,KAAKI,WAAW,MAEf,OAAOH,gBAAgB,cAAe,OAAOA,gBAAgB,YAAYA,gBAAgB,SAE1F,OAAOC,aAAa,aAElB,OAAOC,cAAc,YACrBA,cAAc,QACd,gBAAgBA,aAChB,kBAAkBA,aAElBA,cAAcE;AAEpB;AAEA,SAAgBC,mBAAmBC,MAAsB;CAqBvD,OAAOA;AACT"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/compat/builders/utils.ts
|
|
2
2
|
function isMaybeIdentifier(maybeIdentifier) {
|
|
3
3
|
return Boolean(maybeIdentifier !== null && typeof maybeIdentifier === "object" && ("id" in maybeIdentifier && "type" in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type || maybeIdentifier.lid));
|
|
4
4
|
}
|
|
@@ -6,6 +6,5 @@ function normalizeModelName(type) {
|
|
|
6
6
|
return type;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
//#endregion
|
|
10
9
|
export { normalizeModelName as n, isMaybeIdentifier as t };
|
|
11
|
-
//# sourceMappingURL=utils-
|
|
10
|
+
//# sourceMappingURL=utils-_O0MjUTU.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-
|
|
1
|
+
{"version":3,"file":"utils-_O0MjUTU.js","names":["dasherize","isMaybeIdentifier","maybeIdentifier","Boolean","id","type","lid","normalizeModelName"],"sources":["../../../src/compat/builders/utils.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { DEPRECATE_NON_STRICT_TYPES } from '@warp-drive/core/build-config/deprecations';\nimport type { ResourceIdentifierObject } from '@warp-drive/core/types/spec/json-api-raw';\nimport { dasherize } from '@warp-drive/utilities/string';\n\nexport function isMaybeIdentifier(\n maybeIdentifier: string | ResourceIdentifierObject\n): maybeIdentifier is ResourceIdentifierObject {\n return Boolean(\n maybeIdentifier !== null &&\n typeof maybeIdentifier === 'object' &&\n (('id' in maybeIdentifier && 'type' in maybeIdentifier && maybeIdentifier.id && maybeIdentifier.type) ||\n maybeIdentifier.lid)\n );\n}\n\nexport function normalizeModelName(type: string): string {\n if (DEPRECATE_NON_STRICT_TYPES) {\n const result = dasherize(type);\n\n deprecate(\n `The resource type '${type}' is not normalized. Update your application code to use '${result}' instead of '${type}'.`,\n result === type,\n {\n id: 'ember-data:deprecate-non-strict-types',\n until: '6.0',\n for: 'ember-data',\n since: {\n available: '4.13',\n enabled: '5.3',\n },\n }\n );\n\n return result;\n }\n\n return type;\n}\n"],"mappings":";AAMA,SAAgBC,kBACdC,iBAC6C;CAC7C,OAAOC,QACLD,oBAAoB,QACpB,OAAOA,oBAAoB,aACzB,QAAQA,mBAAmB,UAAUA,mBAAmBA,gBAAgBE,MAAMF,gBAAgBG,QAC9FH,gBAAgBI,IACpB;AACF;AAEA,SAAgBC,mBAAmBF,MAAsB;CAqBvD,OAAOA;AACT"}
|