@warp-drive/utilities 5.9.0-beta.0 → 5.9.0-beta.2

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.
Files changed (158) hide show
  1. package/cjs-dist/string.cjs +448 -0
  2. package/cjs-dist/string.cjs.map +1 -0
  3. package/dist/-private.d.ts +12 -0
  4. package/dist/-private.d.ts.map +1 -0
  5. package/dist/-private.js +2 -6
  6. package/dist/active-record.d.ts +260 -0
  7. package/dist/active-record.d.ts.map +1 -0
  8. package/dist/active-record.js +254 -379
  9. package/dist/active-record.js.map +1 -0
  10. package/dist/builder-utils-BkXwUT0x.js +16 -0
  11. package/dist/builder-utils-BkXwUT0x.js.map +1 -0
  12. package/dist/derivations.d.ts +30 -0
  13. package/dist/derivations.d.ts.map +1 -0
  14. package/dist/derivations.js +26 -26
  15. package/dist/derivations.js.map +1 -0
  16. package/dist/handlers.d.ts +283 -0
  17. package/dist/handlers.d.ts.map +1 -0
  18. package/dist/handlers.js +240 -283
  19. package/dist/handlers.js.map +1 -0
  20. package/dist/index-BeMAuqgZ.d.ts +462 -0
  21. package/dist/index-BeMAuqgZ.d.ts.map +1 -0
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.js +357 -335
  24. package/dist/index.js.map +1 -0
  25. package/dist/inflections-DzBsjJqj.js +80 -0
  26. package/dist/inflections-DzBsjJqj.js.map +1 -0
  27. package/dist/json-api.d.ts +496 -0
  28. package/dist/json-api.d.ts.map +1 -0
  29. package/dist/json-api.js +470 -706
  30. package/dist/json-api.js.map +1 -0
  31. package/dist/rest.d.ts +258 -0
  32. package/dist/rest.d.ts.map +1 -0
  33. package/dist/rest.js +254 -377
  34. package/dist/rest.js.map +1 -0
  35. package/dist/string-CWmAluxh.js +290 -0
  36. package/dist/string-CWmAluxh.js.map +1 -0
  37. package/dist/string.d.ts +165 -0
  38. package/dist/string.d.ts.map +1 -0
  39. package/dist/string.js +2 -427
  40. package/dist/unpkg/dev/-private.js +2 -6
  41. package/dist/unpkg/dev/active-record.js +253 -378
  42. package/dist/unpkg/dev/active-record.js.map +1 -0
  43. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js +16 -0
  44. package/dist/unpkg/dev/builder-utils-BkXwUT0x.js.map +1 -0
  45. package/dist/unpkg/dev/derivations.js +26 -26
  46. package/dist/unpkg/dev/derivations.js.map +1 -0
  47. package/dist/unpkg/dev/handlers.js +238 -282
  48. package/dist/unpkg/dev/handlers.js.map +1 -0
  49. package/dist/unpkg/dev/index.js +356 -336
  50. package/dist/unpkg/dev/index.js.map +1 -0
  51. package/dist/unpkg/dev/inflections-DzBsjJqj.js +80 -0
  52. package/dist/unpkg/dev/inflections-DzBsjJqj.js.map +1 -0
  53. package/dist/unpkg/dev/json-api.js +469 -706
  54. package/dist/unpkg/dev/json-api.js.map +1 -0
  55. package/dist/unpkg/dev/rest.js +253 -376
  56. package/dist/unpkg/dev/rest.js.map +1 -0
  57. package/dist/unpkg/dev/string-j4ur-TDs.js +289 -0
  58. package/dist/unpkg/dev/string-j4ur-TDs.js.map +1 -0
  59. package/dist/unpkg/dev/string.js +3 -1
  60. package/dist/unpkg/dev-deprecated/-private.js +2 -6
  61. package/dist/unpkg/dev-deprecated/active-record.js +253 -378
  62. package/dist/unpkg/dev-deprecated/active-record.js.map +1 -0
  63. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js +16 -0
  64. package/dist/unpkg/dev-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  65. package/dist/unpkg/dev-deprecated/derivations.js +26 -26
  66. package/dist/unpkg/dev-deprecated/derivations.js.map +1 -0
  67. package/dist/unpkg/dev-deprecated/handlers.js +238 -282
  68. package/dist/unpkg/dev-deprecated/handlers.js.map +1 -0
  69. package/dist/unpkg/dev-deprecated/index.js +356 -336
  70. package/dist/unpkg/dev-deprecated/index.js.map +1 -0
  71. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js +80 -0
  72. package/dist/unpkg/dev-deprecated/inflections-DzBsjJqj.js.map +1 -0
  73. package/dist/unpkg/dev-deprecated/json-api.js +469 -706
  74. package/dist/unpkg/dev-deprecated/json-api.js.map +1 -0
  75. package/dist/unpkg/dev-deprecated/rest.js +253 -376
  76. package/dist/unpkg/dev-deprecated/rest.js.map +1 -0
  77. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js +289 -0
  78. package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +1 -0
  79. package/dist/unpkg/dev-deprecated/string.js +3 -1
  80. package/dist/unpkg/prod/-private.js +2 -6
  81. package/dist/unpkg/prod/active-record.js +236 -351
  82. package/dist/unpkg/prod/active-record.js.map +1 -0
  83. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js +16 -0
  84. package/dist/unpkg/prod/builder-utils-BkXwUT0x.js.map +1 -0
  85. package/dist/unpkg/prod/derivations.js +26 -26
  86. package/dist/unpkg/prod/derivations.js.map +1 -0
  87. package/dist/unpkg/prod/handlers.js +231 -272
  88. package/dist/unpkg/prod/handlers.js.map +1 -0
  89. package/dist/unpkg/prod/index.js +265 -215
  90. package/dist/unpkg/prod/index.js.map +1 -0
  91. package/dist/unpkg/prod/inflections-DzBsjJqj.js +80 -0
  92. package/dist/unpkg/prod/inflections-DzBsjJqj.js.map +1 -0
  93. package/dist/unpkg/prod/json-api.js +446 -669
  94. package/dist/unpkg/prod/json-api.js.map +1 -0
  95. package/dist/unpkg/prod/rest.js +236 -349
  96. package/dist/unpkg/prod/rest.js.map +1 -0
  97. package/dist/unpkg/prod/string-T1ahjLdj.js +283 -0
  98. package/dist/unpkg/prod/string-T1ahjLdj.js.map +1 -0
  99. package/dist/unpkg/prod/string.js +3 -1
  100. package/dist/unpkg/prod-deprecated/-private.js +2 -6
  101. package/dist/unpkg/prod-deprecated/active-record.js +236 -351
  102. package/dist/unpkg/prod-deprecated/active-record.js.map +1 -0
  103. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js +16 -0
  104. package/dist/unpkg/prod-deprecated/builder-utils-BkXwUT0x.js.map +1 -0
  105. package/dist/unpkg/prod-deprecated/derivations.js +26 -26
  106. package/dist/unpkg/prod-deprecated/derivations.js.map +1 -0
  107. package/dist/unpkg/prod-deprecated/handlers.js +231 -272
  108. package/dist/unpkg/prod-deprecated/handlers.js.map +1 -0
  109. package/dist/unpkg/prod-deprecated/index.js +265 -215
  110. package/dist/unpkg/prod-deprecated/index.js.map +1 -0
  111. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js +80 -0
  112. package/dist/unpkg/prod-deprecated/inflections-DzBsjJqj.js.map +1 -0
  113. package/dist/unpkg/prod-deprecated/json-api.js +446 -669
  114. package/dist/unpkg/prod-deprecated/json-api.js.map +1 -0
  115. package/dist/unpkg/prod-deprecated/rest.js +236 -349
  116. package/dist/unpkg/prod-deprecated/rest.js.map +1 -0
  117. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js +283 -0
  118. package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +1 -0
  119. package/dist/unpkg/prod-deprecated/string.js +3 -1
  120. package/package.json +20 -23
  121. package/declarations/-private/active-record/find-record.d.ts +0 -64
  122. package/declarations/-private/active-record/query.d.ts +0 -53
  123. package/declarations/-private/active-record/save-record.d.ts +0 -146
  124. package/declarations/-private/builder-utils.d.ts +0 -4
  125. package/declarations/-private/handlers/auto-compress.d.ts +0 -158
  126. package/declarations/-private/handlers/gated.d.ts +0 -19
  127. package/declarations/-private/handlers/meta-doc.d.ts +0 -47
  128. package/declarations/-private/handlers/utils.d.ts +0 -41
  129. package/declarations/-private/json-api/-utils.d.ts +0 -109
  130. package/declarations/-private/json-api/find-record.d.ts +0 -84
  131. package/declarations/-private/json-api/query.d.ts +0 -100
  132. package/declarations/-private/json-api/save-record.d.ts +0 -228
  133. package/declarations/-private/json-api/serialize.d.ts +0 -70
  134. package/declarations/-private/rest/find-record.d.ts +0 -62
  135. package/declarations/-private/rest/query.d.ts +0 -53
  136. package/declarations/-private/rest/save-record.d.ts +0 -146
  137. package/declarations/-private/string/inflect.d.ts +0 -82
  138. package/declarations/-private/string/inflections.d.ts +0 -9
  139. package/declarations/-private/string/transform.d.ts +0 -77
  140. package/declarations/-private.d.ts +0 -1
  141. package/declarations/active-record.d.ts +0 -3
  142. package/declarations/derivations.d.ts +0 -27
  143. package/declarations/handlers.d.ts +0 -10
  144. package/declarations/index.d.ts +0 -208
  145. package/declarations/json-api.d.ts +0 -5
  146. package/declarations/rest.d.ts +0 -3
  147. package/declarations/string.d.ts +0 -14
  148. package/dist/builder-utils-Donkk-BZ.js +0 -22
  149. package/dist/inflect-BSG696t-.js +0 -344
  150. package/dist/string.cjs +0 -430
  151. package/dist/unpkg/dev/builder-utils-Donkk-BZ.js +0 -22
  152. package/dist/unpkg/dev/inflect-BEv8WqY1.js +0 -343
  153. package/dist/unpkg/dev-deprecated/builder-utils-Donkk-BZ.js +0 -22
  154. package/dist/unpkg/dev-deprecated/inflect-BEv8WqY1.js +0 -343
  155. package/dist/unpkg/prod/builder-utils-Donkk-BZ.js +0 -22
  156. package/dist/unpkg/prod/inflect-Dh9dyEYx.js +0 -333
  157. package/dist/unpkg/prod-deprecated/builder-utils-Donkk-BZ.js +0 -22
  158. package/dist/unpkg/prod-deprecated/inflect-Dh9dyEYx.js +0 -333
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["getOrSetGlobal","macroCondition","getGlobalConfig","CONFIG","host","namespace","setBuildURLConfig","config","WarpDrive","env","DEBUG","test","Error","endsWith","startsWith","OPERATIONS_WITH_PRIMARY_RECORDS","Set","isOperationWithPrimaryRecord","options","has","op","hasResourcePath","resourcePath","length","resourcePathForType","identifiers","type","identifier","buildBaseURL","urlOptions","Object","assign","Array","isArray","every","i","id","idPath","encodeURIComponent","fieldPath","String","join","includes","hasHost","url","filter","Boolean","DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS","arrayFormat","handleInclude","include","split","filterEmpty","source","result","key","value","undefined","sortQueryParams","params","opts","paramsIsObject","URLSearchParams","urlParams","dictionaryParams","forEach","hasExisting","existingValue","push","sortedKeys","keys","sort","v","append","buildQueryParams","toString"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @module\n * @mergeModuleWith <project>\n */\n\nimport { assert } from '@warp-drive/core/build-config/macros';\nimport { getOrSetGlobal } from '@warp-drive/core/types/-private';\nimport type { QueryParamsSerializationOptions, QueryParamsSource, Serializable } from '@warp-drive/core/types/params';\n\n// prevents the final constructed object from needing to add\n// host and namespace which are provided by the final consuming\n// class to the prototype which can result in overwrite errors\n\n/**\n * The global configuration used by {@link buildBaseURL} when a call does\n * not provide its own `host`/`namespace`. Set via {@link setBuildURLConfig}.\n *\n * @public\n */\nexport interface BuildURLConfig {\n /**\n * The scheme, domain and port (if any) to prefix built URLs with, e.g. `'https://api.example.com'`.\n */\n host: string | null;\n /**\n * The path segment to insert between `host` and the resource path, e.g. `'api/v1'`.\n */\n namespace: string | null;\n}\n\nconst CONFIG: BuildURLConfig = getOrSetGlobal('CONFIG', {\n host: '',\n namespace: '',\n});\n\n/**\n * Sets the global configuration for `buildBaseURL`\n * for host and namespace values for the application.\n *\n * These values may still be overridden by passing\n * them to buildBaseURL directly.\n *\n * This method may be called as many times as needed.\n * host values of `''` or `'/'` are equivalent.\n *\n * Except for the value of `/` as host, host should not\n * end with `/`.\n *\n * namespace should not start or end with a `/`.\n *\n * ```ts\n * type BuildURLConfig = {\n * host: string;\n * namespace: string'\n * }\n * ```\n *\n * Example:\n *\n * ```ts\n * import { setBuildURLConfig } from '@warp-drive/utilities';\n *\n * setBuildURLConfig({\n * host: 'https://api.example.com',\n * namespace: 'api/v1'\n * });\n * ```\n *\n * @public\n */\nexport function setBuildURLConfig(config: BuildURLConfig): void {\n assert(`setBuildURLConfig: You must pass a config object`, config);\n assert(\n `setBuildURLConfig: You must pass a config object with a 'host' or 'namespace' property`,\n 'host' in config || 'namespace' in config\n );\n\n CONFIG.host = config.host || '';\n CONFIG.namespace = config.namespace || '';\n\n assert(\n `buildBaseURL: host must NOT end with '/', received '${CONFIG.host}'`,\n CONFIG.host === '/' || !CONFIG.host.endsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT start with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.startsWith('/')\n );\n assert(\n `buildBaseURL: namespace must NOT end with '/', received '${CONFIG.namespace}'`,\n !CONFIG.namespace.endsWith('/')\n );\n}\n\n/**\n * {@link buildBaseURL} options for a `findRecord` request.\n *\n * @public\n */\nexport interface FindRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRecord';\n /**\n * The type and id of the record to find.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `query` request.\n *\n * @public\n */\nexport interface QueryUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'query';\n /**\n * The type of the records to query.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `findMany` request.\n *\n * @public\n */\nexport interface FindManyUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findMany';\n /**\n * The type and id of each record to find.\n */\n identifiers: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n }[];\n /**\n * The path segment for the resource, defaults to the first identifier's `type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n/**\n * {@link buildBaseURL} options for a `findRelatedCollection` request.\n *\n * @public\n */\nexport interface FindRelatedCollectionUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRelatedCollection';\n /**\n * The type and id of the record whose relationship is being fetched.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The relationship field name, appended to the resource path.\n */\n fieldPath: string;\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `findRelatedRecord` request.\n *\n * @public\n */\nexport interface FindRelatedResourceUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'findRelatedRecord';\n /**\n * The type and id of the record whose relationship is being fetched.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The relationship field name, appended to the resource path.\n */\n fieldPath: string;\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `createRecord` request.\n *\n * @public\n */\nexport interface CreateRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'createRecord';\n /**\n * The type of the record being created.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for an `updateRecord` request.\n *\n * @public\n */\nexport interface UpdateRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'updateRecord';\n /**\n * The type and id of the record being updated.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for a `deleteRecord` request.\n *\n * @public\n */\nexport interface DeleteRecordUrlOptions {\n /**\n * The request operation this URL is for.\n */\n op: 'deleteRecord';\n /**\n * The type and id of the record being deleted.\n */\n identifier: {\n /**\n * The resource type.\n */\n type: string;\n /**\n * The resource id.\n */\n id: string;\n };\n /**\n * The path segment for the resource, defaults to `identifier.type` if not provided.\n */\n resourcePath?: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * {@link buildBaseURL} options for building a URL directly from a `resourcePath`\n * without an associated request operation.\n *\n * @public\n */\nexport interface GenericUrlOptions {\n /**\n * The path segment for the resource.\n */\n resourcePath: string;\n /**\n * Overrides the globally configured host for this call only.\n */\n host?: string;\n /**\n * Overrides the globally configured namespace for this call only.\n */\n namespace?: string;\n}\n\n/**\n * The union of all `op`-specific option shapes accepted by {@link buildBaseURL}, one of:\n *\n * - {@link FindRecordUrlOptions}\n * - {@link QueryUrlOptions}\n * - {@link FindManyUrlOptions}\n * - {@link FindRelatedCollectionUrlOptions}\n * - {@link FindRelatedResourceUrlOptions}\n * - {@link CreateRecordUrlOptions}\n * - {@link UpdateRecordUrlOptions}\n * - {@link DeleteRecordUrlOptions}\n * - {@link GenericUrlOptions}\n *\n * @public\n */\nexport type UrlOptions =\n | FindRecordUrlOptions\n | QueryUrlOptions\n | FindManyUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | CreateRecordUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions\n | GenericUrlOptions;\n\nconst OPERATIONS_WITH_PRIMARY_RECORDS = new Set([\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n]);\n\nfunction isOperationWithPrimaryRecord(\n options: UrlOptions\n): options is\n | FindRecordUrlOptions\n | FindRelatedCollectionUrlOptions\n | FindRelatedResourceUrlOptions\n | UpdateRecordUrlOptions\n | DeleteRecordUrlOptions {\n return 'op' in options && OPERATIONS_WITH_PRIMARY_RECORDS.has(options.op);\n}\n\nfunction hasResourcePath(options: UrlOptions): options is GenericUrlOptions {\n return 'resourcePath' in options && typeof options.resourcePath === 'string' && options.resourcePath.length > 0;\n}\n\nfunction resourcePathForType(options: UrlOptions): string {\n assert(\n `resourcePathForType: You must pass a valid op as part of options`,\n 'op' in options && typeof options.op === 'string'\n );\n return options.op === 'findMany' ? options.identifiers[0].type : options.identifier.type;\n}\n\n/**\n * Builds a URL for a request based on the provided options.\n * Does not include support for building query params (see `buildQueryParams`)\n * so that it may be composed cleanly with other query-params strategies.\n *\n * Usage:\n *\n * ```ts\n * import { buildBaseURL } from '@warp-drive/utilities';\n *\n * const url = buildBaseURL({\n * host: 'https://api.example.com',\n * namespace: 'api/v1',\n * resourcePath: 'emberDevelopers',\n * op: 'query',\n * identifier: { type: 'ember-developer' }\n * });\n *\n * // => 'https://api.example.com/api/v1/emberDevelopers'\n * ```\n *\n * On the surface this may seem like a lot of work to do something simple, but\n * it is designed to be composable with other utilities and interfaces that the\n * average product engineer will never need to see or use.\n *\n * A few notes:\n *\n * - `resourcePath` is optional, but if it is not provided, `identifier.type` will be used.\n * - `host` and `namespace` are optional, but if they are not provided, the values globally\n * configured via `setBuildURLConfig` will be used.\n * - `op` is required and must be one of the following:\n * - 'findRecord' 'query' 'findMany' 'findRelatedCollection' 'findRelatedRecord'` 'createRecord' 'updateRecord' 'deleteRecord'\n * - Depending on the value of `op`, `identifier` or `identifiers` will be required.\n *\n * @public\n */\nexport function buildBaseURL(urlOptions: UrlOptions): string {\n const options = Object.assign(\n {\n host: CONFIG.host,\n namespace: CONFIG.namespace,\n },\n urlOptions\n );\n assert(\n `buildBaseURL: You must pass \\`op\\` as part of options`,\n hasResourcePath(options) || (typeof options.op === 'string' && options.op.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifier\\` as part of options`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (options.identifier && typeof options.identifier === 'object')\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (options.identifiers &&\n Array.isArray(options.identifiers) &&\n options.identifiers.length > 0 &&\n options.identifiers.every((i) => i && typeof i === 'object'))\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'id'`,\n hasResourcePath(options) ||\n !isOperationWithPrimaryRecord(options) ||\n (typeof options.identifier.id === 'string' && options.identifier.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass \\`identifiers\\` as part of options`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n options.identifiers.every((i) => typeof i.id === 'string' && i.id.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifier\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op === 'findMany' ||\n (typeof options.identifier.type === 'string' && options.identifier.type.length > 0)\n );\n assert(\n `buildBaseURL: You must pass valid \\`identifiers\\` as part of options, expected 'type'`,\n hasResourcePath(options) ||\n options.op !== 'findMany' ||\n (typeof options.identifiers[0].type === 'string' && options.identifiers[0].type.length > 0)\n );\n\n // prettier-ignore\n const idPath: string =\n isOperationWithPrimaryRecord(options) ? encodeURIComponent(options.identifier.id)\n : '';\n const resourcePath = options.resourcePath || resourcePathForType(options);\n const { host, namespace } = options;\n const fieldPath = 'fieldPath' in options ? options.fieldPath : '';\n\n assert(\n `buildBaseURL: You tried to build a url for a ${String(\n 'op' in options ? options.op + ' ' : ''\n )}request to ${resourcePath} but resourcePath must be set or op must be one of \"${[\n 'findRecord',\n 'findRelatedRecord',\n 'findRelatedCollection',\n 'updateRecord',\n 'deleteRecord',\n 'createRecord',\n 'query',\n 'findMany',\n ].join('\",\"')}\".`,\n hasResourcePath(options) ||\n [\n 'findRecord',\n 'query',\n 'findMany',\n 'findRelatedCollection',\n 'findRelatedRecord',\n 'createRecord',\n 'updateRecord',\n 'deleteRecord',\n ].includes(options.op)\n );\n\n assert(`buildBaseURL: host must NOT end with '/', received '${host}'`, host === '/' || !host.endsWith('/'));\n assert(`buildBaseURL: namespace must NOT start with '/', received '${namespace}'`, !namespace.startsWith('/'));\n assert(`buildBaseURL: namespace must NOT end with '/', received '${namespace}'`, !namespace.endsWith('/'));\n assert(\n `buildBaseURL: resourcePath must NOT start with '/', received '${resourcePath}'`,\n !resourcePath.startsWith('/')\n );\n assert(`buildBaseURL: resourcePath must NOT end with '/', received '${resourcePath}'`, !resourcePath.endsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT start with '/', received '${fieldPath}'`, !fieldPath.startsWith('/'));\n assert(`buildBaseURL: fieldPath must NOT end with '/', received '${fieldPath}'`, !fieldPath.endsWith('/'));\n assert(`buildBaseURL: idPath must NOT start with '/', received '${idPath}'`, !idPath.startsWith('/'));\n assert(`buildBaseURL: idPath must NOT end with '/', received '${idPath}'`, !idPath.endsWith('/'));\n\n const hasHost = host !== '' && host !== '/';\n const url = [hasHost ? host : '', namespace, resourcePath, idPath, fieldPath].filter(Boolean).join('/');\n return hasHost ? url : `/${url}`;\n}\n\nconst DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS: QueryParamsSerializationOptions = {\n arrayFormat: 'comma',\n};\n\nfunction handleInclude(include: string | string[]): string[] {\n assert(\n `Expected include to be a string or array, got ${typeof include}`,\n typeof include === 'string' || Array.isArray(include)\n );\n return typeof include === 'string' ? include.split(',') : include;\n}\n\n/**\n * filter out keys of an object that have falsy values or point to empty arrays\n * returning a new object with only those keys that have truthy values / non-empty arrays\n *\n * @public\n * @param source object to filter keys with empty values from\n * @return A new object with the keys that contained empty values removed\n */\nexport function filterEmpty(source: Record<string, Serializable>): Record<string, Serializable> {\n const result: Record<string, Serializable> = {};\n for (const key in source) {\n const value = source[key];\n // Allow `0` and `false` but filter falsy values that indicate \"empty\"\n if (value !== undefined && value !== null && value !== '') {\n if (!Array.isArray(value) || value.length > 0) {\n result[key] = source[key];\n }\n }\n }\n return result;\n}\n\n/**\n * Sorts query params by both key and value returning a new URLSearchParams\n * object with the keys inserted in sorted order.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `&ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `&ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `&ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `&ids=1,2`\n *\n * @public\n * @return A {@link URLSearchParams} with keys inserted in sorted order\n */\nexport function sortQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): URLSearchParams {\n const opts = Object.assign({}, DEFAULT_QUERY_PARAMS_SERIALIZATION_OPTIONS, options);\n const paramsIsObject = !(params instanceof URLSearchParams);\n const urlParams = new URLSearchParams();\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? params : {};\n\n if (!paramsIsObject) {\n params.forEach((value, key) => {\n const hasExisting = key in dictionaryParams;\n if (!hasExisting) {\n dictionaryParams[key] = value;\n } else {\n const existingValue = dictionaryParams[key];\n if (Array.isArray(existingValue)) {\n existingValue.push(value);\n } else {\n dictionaryParams[key] = [existingValue, value];\n }\n }\n });\n }\n\n if ('include' in dictionaryParams) {\n dictionaryParams.include = handleInclude(dictionaryParams.include as string | string[]);\n }\n\n const sortedKeys = Object.keys(dictionaryParams).sort();\n sortedKeys.forEach((key) => {\n const value = dictionaryParams[key];\n if (Array.isArray(value)) {\n value.sort();\n switch (opts.arrayFormat) {\n case 'indices':\n value.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n value.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n value.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, value.join(','));\n return;\n }\n } else {\n urlParams.append(key, String(value));\n }\n });\n\n return urlParams;\n}\n\n/**\n * Sorts query params by both key and value, returning a query params string\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * Options:\n * - arrayFormat: 'bracket' | 'indices' | 'repeat' | 'comma'\n *\n * 'bracket': appends [] to the key for every value e.g. `ids[]=1&ids[]=2`\n * 'indices': appends [i] to the key for every value e.g. `ids[0]=1&ids[1]=2`\n * 'repeat': appends the key for every value e.g. `ids=1&ids=2`\n * 'comma' (default): appends the key once with a comma separated list of values e.g. `ids=1,2`\n *\n * @public\n * @return A sorted query params string without the leading `?`\n */\nexport function buildQueryParams(params: QueryParamsSource, options?: QueryParamsSerializationOptions): string {\n return sortQueryParams(params, options).toString();\n}\n"],"mappings":";;;;;;;;;;;;;;AA8BA,MAAMG,SAAyBH,eAAe,UAAU;CACtDI,MAAM;CACNC,WAAW;AACb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCD,SAAgBC,kBAAkBC,QAA8B;CAC9DN,eAAAC,gBAAA,CAAA,CAAAM,UAAAC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MAAO,kDAAkD;CAAA,EAAA,CAAEL,MAAM;CACjEN,eAAAC,gBAAA,CAAA,CAAAM,UAAAC,IAAAC,KAAA,OAAAC,SAAA;EAAA,IAAA,CAAAA,MAAA,MAAA,IAAAC,MACE,wFAAwF;CAAA,EAAA,CACxF,UAAUL,UAAU,eAAeA,MAAM;CAG3CJ,OAAOC,OAAOG,OAAOH,QAAQ;CAC7BD,OAAOE,YAAYE,OAAOF,aAAa;CAEvCJ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M;MACnBT,UAAUU,OAAO,GAAGlB,IAAG,KAAMf,OAAOgC,CAAC,CAAC;KACxC,CAAC;KACD;IACF,KAAK;KACHhB,MAAMS,SAASO,MAAM;MACnBT,UAAUU,OAAOlB,KAAKf,OAAOgC,CAAC,CAAC;KACjC,CAAC;KACD;IAEF;KACET,UAAUU,OAAOlB,KAAKC,MAAMf,KAAK,GAAG,CAAC;KACrC;GACJ;EACF,OACEsB,UAAUU,OAAOlB,KAAKf,OAAOgB,KAAK,CAAC;CAEvC,CAAC;CAED,OAAOO;AACT;;;;;;;;;;;;;;;;;AAkBA,SAAgBW,iBAAiBf,QAA2BzC,SAAmD;CAC7G,OAAOwC,gBAAgBC,QAAQzC,OAAO,CAAC,CAACyD,SAAS;AACnD"}
@@ -0,0 +1,80 @@
1
+ //#region src/-private/string/inflections.ts
2
+ const defaultRules = {
3
+ plurals: [
4
+ [/$/, "s"],
5
+ [/s$/i, "s"],
6
+ [/^(ax|test)is$/i, "$1es"],
7
+ [/(octop|vir)us$/i, "$1i"],
8
+ [/(octop|vir)i$/i, "$1i"],
9
+ [/(alias|status|bonus)$/i, "$1es"],
10
+ [/(tu|bu)s$/i, "$1ses"],
11
+ [/(buffal|tomat)o$/i, "$1oes"],
12
+ [/([ti])um$/i, "$1a"],
13
+ [/([ti])a$/i, "$1a"],
14
+ [/sis$/i, "ses"],
15
+ [/(?:([^f])fe|([lr])f)$/i, "$1$2ves"],
16
+ [/(hive)$/i, "$1s"],
17
+ [/([^aeiouy]|qu)y$/i, "$1ies"],
18
+ [/(x|ch|ss|sh)$/i, "$1es"],
19
+ [/(matr|vert|ind)(?:ix|ex)$/i, "$1ices"],
20
+ [/^(m|l)ouse$/i, "$1ice"],
21
+ [/^(m|l)ice$/i, "$1ice"],
22
+ [/^(ox)$/i, "$1en"],
23
+ [/^(oxen)$/i, "$1"],
24
+ [/(quiz)$/i, "$1zes"]
25
+ ],
26
+ singular: [
27
+ [/s$/i, ""],
28
+ [/(ss)$/i, "$1"],
29
+ [/(n)ews$/i, "$1ews"],
30
+ [/([ti])a$/i, "$1um"],
31
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, "$1sis"],
32
+ [/(^analy)(sis|ses)$/i, "$1sis"],
33
+ [/([^f])ves$/i, "$1fe"],
34
+ [/(hive)s$/i, "$1"],
35
+ [/(tive)s$/i, "$1"],
36
+ [/([lr])ves$/i, "$1f"],
37
+ [/([^aeiouy]|qu)ies$/i, "$1y"],
38
+ [/(s)eries$/i, "$1eries"],
39
+ [/(m)ovies$/i, "$1ovie"],
40
+ [/(x|ch|ss|sh)es$/i, "$1"],
41
+ [/^(m|l)ice$/i, "$1ouse"],
42
+ [/(tus|bus)(es)?$/i, "$1"],
43
+ [/(o)es$/i, "$1"],
44
+ [/(shoe)s$/i, "$1"],
45
+ [/(cris|test)(is|es)$/i, "$1is"],
46
+ [/^(a)x[ie]s$/i, "$1xis"],
47
+ [/(octop|vir)(us|i)$/i, "$1us"],
48
+ [/(alias|status|bonus)(es)?$/i, "$1"],
49
+ [/^(ox)en/i, "$1"],
50
+ [/(vert|ind)ices$/i, "$1ex"],
51
+ [/(matr)ices$/i, "$1ix"],
52
+ [/(quiz)zes$/i, "$1"],
53
+ [/(database)s$/i, "$1"]
54
+ ],
55
+ irregularPairs: [
56
+ ["person", "people"],
57
+ ["man", "men"],
58
+ ["child", "children"],
59
+ ["sex", "sexes"],
60
+ ["move", "moves"],
61
+ ["cow", "kine"],
62
+ ["zombie", "zombies"]
63
+ ],
64
+ uncountable: [
65
+ "equipment",
66
+ "information",
67
+ "rice",
68
+ "money",
69
+ "species",
70
+ "series",
71
+ "fish",
72
+ "sheep",
73
+ "jeans",
74
+ "police"
75
+ ]
76
+ };
77
+
78
+ //#endregion
79
+ export { defaultRules as t };
80
+ //# sourceMappingURL=inflections-DzBsjJqj.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inflections-DzBsjJqj.js","names":[],"sources":["../src/-private/string/inflections.ts"],"sourcesContent":["export type RulesArray = Array<[RegExp, string]>;\ntype DefaultRulesType = {\n plurals: RulesArray;\n singular: RulesArray;\n irregularPairs: Array<[string, string]>;\n uncountable: string[];\n};\n\nexport const defaultRules: DefaultRulesType = {\n plurals: [\n [/$/, 's'],\n [/s$/i, 's'],\n [/^(ax|test)is$/i, '$1es'],\n [/(octop|vir)us$/i, '$1i'],\n [/(octop|vir)i$/i, '$1i'],\n [/(alias|status|bonus)$/i, '$1es'],\n [/(tu|bu)s$/i, '$1ses'],\n [/(buffal|tomat)o$/i, '$1oes'],\n [/([ti])um$/i, '$1a'],\n [/([ti])a$/i, '$1a'],\n [/sis$/i, 'ses'],\n [/(?:([^f])fe|([lr])f)$/i, '$1$2ves'],\n [/(hive)$/i, '$1s'],\n [/([^aeiouy]|qu)y$/i, '$1ies'],\n [/(x|ch|ss|sh)$/i, '$1es'],\n [/(matr|vert|ind)(?:ix|ex)$/i, '$1ices'],\n [/^(m|l)ouse$/i, '$1ice'],\n [/^(m|l)ice$/i, '$1ice'],\n [/^(ox)$/i, '$1en'],\n [/^(oxen)$/i, '$1'],\n [/(quiz)$/i, '$1zes'],\n ],\n\n singular: [\n [/s$/i, ''],\n [/(ss)$/i, '$1'],\n [/(n)ews$/i, '$1ews'],\n [/([ti])a$/i, '$1um'],\n [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '$1sis'],\n [/(^analy)(sis|ses)$/i, '$1sis'],\n [/([^f])ves$/i, '$1fe'],\n [/(hive)s$/i, '$1'],\n [/(tive)s$/i, '$1'],\n [/([lr])ves$/i, '$1f'],\n [/([^aeiouy]|qu)ies$/i, '$1y'],\n [/(s)eries$/i, '$1eries'],\n [/(m)ovies$/i, '$1ovie'],\n [/(x|ch|ss|sh)es$/i, '$1'],\n [/^(m|l)ice$/i, '$1ouse'],\n [/(tus|bus)(es)?$/i, '$1'],\n [/(o)es$/i, '$1'],\n [/(shoe)s$/i, '$1'],\n [/(cris|test)(is|es)$/i, '$1is'],\n [/^(a)x[ie]s$/i, '$1xis'],\n [/(octop|vir)(us|i)$/i, '$1us'],\n [/(alias|status|bonus)(es)?$/i, '$1'],\n [/^(ox)en/i, '$1'],\n [/(vert|ind)ices$/i, '$1ex'],\n [/(matr)ices$/i, '$1ix'],\n [/(quiz)zes$/i, '$1'],\n [/(database)s$/i, '$1'],\n ],\n\n irregularPairs: [\n ['person', 'people'],\n ['man', 'men'],\n ['child', 'children'],\n ['sex', 'sexes'],\n ['move', 'moves'],\n ['cow', 'kine'],\n ['zombie', 'zombies'],\n ],\n\n uncountable: ['equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans', 'police'],\n};\n"],"mappings":";AAQA,MAAa,eAAiC;CAC5C,SAAS;EACP,CAAC,KAAK,GAAG;EACT,CAAC,OAAO,GAAG;EACX,CAAC,kBAAkB,MAAM;EACzB,CAAC,mBAAmB,KAAK;EACzB,CAAC,kBAAkB,KAAK;EACxB,CAAC,0BAA0B,MAAM;EACjC,CAAC,cAAc,OAAO;EACtB,CAAC,qBAAqB,OAAO;EAC7B,CAAC,cAAc,KAAK;EACpB,CAAC,aAAa,KAAK;EACnB,CAAC,SAAS,KAAK;EACf,CAAC,0BAA0B,SAAS;EACpC,CAAC,YAAY,KAAK;EAClB,CAAC,qBAAqB,OAAO;EAC7B,CAAC,kBAAkB,MAAM;EACzB,CAAC,8BAA8B,QAAQ;EACvC,CAAC,gBAAgB,OAAO;EACxB,CAAC,eAAe,OAAO;EACvB,CAAC,WAAW,MAAM;EAClB,CAAC,aAAa,IAAI;EAClB,CAAC,YAAY,OAAO;CACtB;CAEA,UAAU;EACR,CAAC,OAAO,EAAE;EACV,CAAC,UAAU,IAAI;EACf,CAAC,YAAY,OAAO;EACpB,CAAC,aAAa,MAAM;EACpB,CAAC,wEAAwE,OAAO;EAChF,CAAC,uBAAuB,OAAO;EAC/B,CAAC,eAAe,MAAM;EACtB,CAAC,aAAa,IAAI;EAClB,CAAC,aAAa,IAAI;EAClB,CAAC,eAAe,KAAK;EACrB,CAAC,uBAAuB,KAAK;EAC7B,CAAC,cAAc,SAAS;EACxB,CAAC,cAAc,QAAQ;EACvB,CAAC,oBAAoB,IAAI;EACzB,CAAC,eAAe,QAAQ;EACxB,CAAC,oBAAoB,IAAI;EACzB,CAAC,WAAW,IAAI;EAChB,CAAC,aAAa,IAAI;EAClB,CAAC,wBAAwB,MAAM;EAC/B,CAAC,gBAAgB,OAAO;EACxB,CAAC,uBAAuB,MAAM;EAC9B,CAAC,+BAA+B,IAAI;EACpC,CAAC,YAAY,IAAI;EACjB,CAAC,oBAAoB,MAAM;EAC3B,CAAC,gBAAgB,MAAM;EACvB,CAAC,eAAe,IAAI;EACpB,CAAC,iBAAiB,IAAI;CACxB;CAEA,gBAAgB;EACd,CAAC,UAAU,QAAQ;EACnB,CAAC,OAAO,KAAK;EACb,CAAC,SAAS,UAAU;EACpB,CAAC,OAAO,OAAO;EACf,CAAC,QAAQ,OAAO;EAChB,CAAC,OAAO,MAAM;EACd,CAAC,UAAU,SAAS;CACtB;CAEA,aAAa;EAAC;EAAa;EAAe;EAAQ;EAAS;EAAW;EAAU;EAAQ;EAAS;EAAS;CAAQ;AACpH"}
@@ -0,0 +1,496 @@
1
+ import { t as BuildURLConfig } from "./index-BeMAuqgZ.js";
2
+ import { ReactiveDataDocument } from "@warp-drive/core/reactive";
3
+ import { TypeFromInstance, TypedRecordInstance } from "@warp-drive/core/types/record";
4
+ import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, PostQueryRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive/core/types/request";
5
+ import { QueryParamsSource } from "@warp-drive/core/types/params";
6
+ import { Cache } from "@warp-drive/core/types/cache";
7
+ import { ResourceKey } from "@warp-drive/core/types/identifier";
8
+ import { Value } from "@warp-drive/core/types/json/raw";
9
+ import { InnerRelationshipDocument, ResourceObject } from "@warp-drive/core/types/spec/json-api-raw";
10
+ //#region src/-private/json-api/find-record.d.ts
11
+ /**
12
+ * Builds request options to fetch a single resource by a known id or identifier
13
+ * configured for the url and header expectations of most JSON:API APIs.
14
+ *
15
+ * :::tabs
16
+ *
17
+ * == Basic Usage
18
+ *
19
+ * ```ts
20
+ * import { findRecord } from '@warp-drive/utilities/json-api';
21
+ * import type { Person } from '#/data/types';
22
+ *
23
+ * const result = await store.request(
24
+ * findRecord<Person>('person', '1')
25
+ * );
26
+ * ```
27
+ *
28
+ * == With Options
29
+ *
30
+ * ```ts
31
+ * import { findRecord } from '@warp-drive/utilities/json-api';
32
+ * import type { Person } from '#/data/types';
33
+ *
34
+ * const data = await store.request(
35
+ * findRecord<Person>(
36
+ * 'person', '1',
37
+ * { include: ['pets', 'friends'] }
38
+ * )
39
+ * );
40
+ * ```
41
+ *
42
+ * == With an Identifier
43
+ *
44
+ * ```ts
45
+ * import { findRecord } from '@warp-drive/utilities/json-api';
46
+ * import type { Person } from '#/data/types';
47
+ *
48
+ * const data = await store.request(
49
+ * findRecord<Person>(
50
+ * { type: 'person', id: '1' },
51
+ * { include: ['pets', 'friends'] }
52
+ * )
53
+ * );
54
+ * ```
55
+ *
56
+ * :::
57
+ *
58
+ * **Supplying Options to Modify the Request Behavior**
59
+ *
60
+ * The following options are supported:
61
+ *
62
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
63
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
64
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
65
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
66
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
67
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
68
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
69
+ * defaulting to `false` if none is configured.
70
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
71
+ *
72
+ * ```ts
73
+ * import { findRecord } from '@warp-drive/utilities/json-api';
74
+ *
75
+ * const data = await store.request(
76
+ * findRecord(
77
+ * 'person', '1',
78
+ * { include: ['pets', 'friends'] },
79
+ * { namespace: 'api/v2' }
80
+ * )
81
+ * );
82
+ * ```
83
+ *
84
+ * @public
85
+ */
86
+ declare function findRecord<T>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
87
+ declare function findRecord(identifier: RemotelyAccessibleIdentifier, options?: FindRecordOptions): FindRecordRequestOptions;
88
+ declare function findRecord<T>(type: TypeFromInstance<T>, id: string, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T>, T>;
89
+ declare function findRecord(type: string, id: string, options?: FindRecordOptions): FindRecordRequestOptions;
90
+ //#endregion
91
+ //#region src/-private/json-api/query.d.ts
92
+ /**
93
+ * Builds request options to query for resources, usually by a primary
94
+ * type, configured for the url and header expectations of most JSON:API APIs.
95
+ *
96
+ * The key difference between this and `postQuery` is that this method will send the query
97
+ * as query params in the url of a "GET" request instead of as the JSON body of a "POST"
98
+ * request.
99
+ *
100
+ * **Basic Usage**
101
+ *
102
+ * ```ts
103
+ * import { query } from '@warp-drive/utilities/json-api';
104
+ *
105
+ * const data = await store.request(query('person'));
106
+ * ```
107
+ *
108
+ * **With Query Params**
109
+ *
110
+ * ```ts
111
+ * import { query } from '@warp-drive/utilities/json-api';
112
+ *
113
+ * const options = query('person', { include: ['pets', 'friends'] });
114
+ * const data = await store.request(options);
115
+ * ```
116
+ *
117
+ * **Supplying Options to Modify the Request Behavior**
118
+ *
119
+ * The following options are supported:
120
+ *
121
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
122
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
123
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
124
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
125
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
126
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
127
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
128
+ * defaulting to `false` if none is configured.
129
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
130
+ *
131
+ * ```ts
132
+ * import { query } from '@warp-drive/utilities/json-api';
133
+ *
134
+ * const options = query('person', { include: ['pets', 'friends'] }, { reload: true });
135
+ * const data = await store.request(options);
136
+ * ```
137
+ *
138
+ * @public
139
+ * @badge Builder
140
+ */
141
+ declare function query<T extends TypedRecordInstance>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions<ReactiveDataDocument<T[]>>;
142
+ declare function query(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): QueryRequestOptions;
143
+ /**
144
+ * Builds request options to query for resources, usually by a primary
145
+ * type, configured for the url and header expectations of most JSON:API APIs.
146
+ *
147
+ * The key difference between this and `query` is that this method will send the query
148
+ * as the JSON body of a "POST" request instead of as query params in the url of a "GET"
149
+ * request.
150
+ *
151
+ * A CacheKey is generated from the url and query params, and used to cache the response
152
+ * in the store.
153
+ *
154
+ * ```ts
155
+ * import { postQuery } from '@warp-drive/utilities/json-api';
156
+ *
157
+ * const options = postQuery('person', { include: ['pets', 'friends'] });
158
+ * const data = await store.request(options);
159
+ * ```
160
+ *
161
+ * **Supplying Options to Modify the Request Behavior**
162
+ *
163
+ * The following options are supported:
164
+ *
165
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
166
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
167
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
168
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
169
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
170
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
171
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
172
+ * defaulting to `false` if none is configured.
173
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
174
+ *
175
+ * ```ts
176
+ * import { postQuery } from '@warp-drive/utilities/json-api';
177
+ *
178
+ * const options = postQuery('person', { include: ['pets', 'friends'] }, { reload: true });
179
+ * const data = await store.request(options);
180
+ * ```
181
+ *
182
+ * @public
183
+ * @param type - the name of the resource type to query
184
+ * @param query - the query params to send with the request
185
+ * @param options - options to modify the request behavior
186
+ */
187
+ declare function postQuery<T>(type: TypeFromInstance<T>, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions<ReactiveDataDocument<T[]>>;
188
+ declare function postQuery(type: string, query?: QueryParamsSource, options?: ConstrainedRequestOptions): PostQueryRequestOptions;
189
+ //#endregion
190
+ //#region src/-private/json-api/save-record.d.ts
191
+ /**
192
+ * :::warning ⚠️ **These Mutation Builders DO NOT Set The Request Body**
193
+ * While this may come as a surprise, the app providing the body ensures that only
194
+ * desired and correctly formatted data is sent with the request.
195
+ * :::
196
+ *
197
+ * Builds request options to delete record for resources,
198
+ * configured for the url, method and header expectations of most JSON:API APIs.
199
+ *
200
+ * **Basic Usage**
201
+ *
202
+ * ```ts
203
+ * import { deleteRecord } from '@warp-drive/utilities/json-api';
204
+ *
205
+ * const person = store.peekRecord('person', '1');
206
+ *
207
+ * // mark record as deleted
208
+ * store.deleteRecord(person);
209
+ *
210
+ * // persist deletion
211
+ * const data = await store.request(deleteRecord(person));
212
+ * ```
213
+ *
214
+ * **Supplying Options to Modify the Request Behavior**
215
+ *
216
+ * The following options are supported:
217
+ *
218
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
219
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
220
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
221
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
222
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
223
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
224
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
225
+ * defaulting to `false` if none is configured.
226
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
227
+ *
228
+ * ```ts
229
+ * import { deleteRecord } from '@warp-drive/utilities/json-api';
230
+ *
231
+ * const person = store.peekRecord('person', '1');
232
+ *
233
+ * // mark record as deleted
234
+ * store.deleteRecord(person);
235
+ *
236
+ * // persist deletion
237
+ * const options = deleteRecord(person, { namespace: 'api/v1' });
238
+ * const data = await store.request(options);
239
+ * ```
240
+ *
241
+ * @public
242
+ * @param record
243
+ * @param options
244
+ */
245
+ declare function deleteRecord<T>(record: T, options?: ConstrainedRequestOptions): DeleteRequestOptions<T>;
246
+ declare function deleteRecord(record: unknown, options?: ConstrainedRequestOptions): DeleteRequestOptions;
247
+ /**
248
+ * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
249
+ * While this may come as a surprise, the app providing the body ensures that only
250
+ * desired and correctly formatted data is sent with the request.
251
+ * :::
252
+ *
253
+ * Builds request options to create new record for resources,
254
+ * configured for the url, method and header expectations of most JSON:API APIs.
255
+ *
256
+ * **Basic Usage**
257
+ *
258
+ * ```ts
259
+ * import { cacheKeyFor } from '@warp-drive/core';
260
+ * import { createRecord } from '@warp-drive/utilities/json-api';
261
+ * import type { Person } from '#/data/types';
262
+ *
263
+ * const person = store.createRecord<Person>('person', { name: 'Ted' });
264
+ * const init = createRecord(person);
265
+ * init.body = JSON.stringify(
266
+ * {
267
+ * // it's likely you will want to transform this data
268
+ * // somewhat
269
+ * data: store.cache.peek(cacheKeyFor(person))
270
+ * }
271
+ * );
272
+ * const data = await store.request(init);
273
+ * ```
274
+ *
275
+ * **Supplying Options to Modify the Request Behavior**
276
+ *
277
+ * The following options are supported:
278
+ *
279
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
280
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
281
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
282
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
283
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
284
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
285
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
286
+ * defaulting to `false` if none is configured.
287
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
288
+ *
289
+ * ```ts
290
+ * import { createRecord } from '@warp-drive/utilities/json-api';
291
+ *
292
+ * const person = store.createRecord('person', { name: 'Ted' });
293
+ * const options = createRecord(person, { namespace: 'api/v1' });
294
+ * const data = await store.request(options);
295
+ * ```
296
+ *
297
+ * @public
298
+ * @param record
299
+ * @param options
300
+ */
301
+ declare function createRecord<T>(record: T, options?: ConstrainedRequestOptions): CreateRequestOptions<T>;
302
+ declare function createRecord(record: unknown, options?: ConstrainedRequestOptions): CreateRequestOptions;
303
+ /**
304
+ * :::warning ⚠️ **These Mutation Builders DO NOT Set The Necessary Request Body**
305
+ * While this may come as a surprise, the app providing the body ensures that only
306
+ * desired and correctly formatted data is sent with the request.
307
+ * :::
308
+ *
309
+ * Builds request options to update existing record for resources,
310
+ * configured for the url, method and header expectations of most JSON:API APIs.
311
+ *
312
+ * **Example Usage**
313
+ *
314
+ * ```ts
315
+ * import { cacheKeyFor } from '@warp-drive/core';
316
+ * import { updateRecord } from '@warp-drive/utilities/json-api';
317
+ * import type { EditablePerson } from '#/data/types';
318
+ *
319
+ * const mutable = await checkout<EditablePerson>(person);
320
+ * mutable.name = 'Chris';
321
+ * const init = updateRecord(mutable);
322
+ *
323
+ * init.body = JSON.stringify(
324
+ * // it's likely you will want to transform this data
325
+ * // somewhat, or serialize only specific properties instead
326
+ * serializePatch(store.cache, cacheKeyFor(mutable))
327
+ * );
328
+ * const data = await store.request(init);
329
+ * ```
330
+ *
331
+ *
332
+ * **Supplying Options to Modify the Request Behavior**
333
+ *
334
+ * The following options are supported:
335
+ *
336
+ * - `patch` - Allows caller to specify whether to use a PATCH request instead of a PUT request, defaults to `false`.
337
+ * - `host` - The host to use for the request, defaults to the `host` configured with `setBuildURLConfig`.
338
+ * - `namespace` - The namespace to use for the request, defaults to the `namespace` configured with `setBuildURLConfig`.
339
+ * - `resourcePath` - The resource path to use for the request, defaults to pluralizing the supplied type
340
+ * - `reload` - Whether to forcibly reload the request if it is already in the store, not supplying this
341
+ * option will delegate to the store's CachePolicy, defaulting to `false` if none is configured.
342
+ * - `backgroundReload` - Whether to reload the request if it is already in the store, but to also resolve the
343
+ * promise with the cached value, not supplying this option will delegate to the store's CachePolicy,
344
+ * defaulting to `false` if none is configured.
345
+ * - `urlParamsSetting` - an object containing options for how to serialize the query params (see `buildQueryParams`)
346
+ *
347
+ * ```ts
348
+ * import { updateRecord } from '@warp-drive/utilities/json-api';
349
+ *
350
+ * const person = store.peekRecord('person', '1');
351
+ * person.name = 'Chris';
352
+ * const options = updateRecord(person, { patch: true });
353
+ * const data = await store.request(options);
354
+ * ```
355
+ *
356
+ * @public
357
+ * @param record
358
+ * @param options
359
+ */
360
+ declare function updateRecord<T extends TypedRecordInstance, RT extends TypedRecordInstance = T>(record: T, options?: ConstrainedRequestOptions & {
361
+ patch?: boolean;
362
+ }): UpdateRequestOptions<ReactiveDataDocument<RT>, T>;
363
+ declare function updateRecord(record: unknown, options?: ConstrainedRequestOptions & {
364
+ patch?: boolean;
365
+ }): UpdateRequestOptions;
366
+ //#endregion
367
+ //#region src/-private/json-api/serialize.d.ts
368
+ type ChangedRelationshipData = InnerRelationshipDocument;
369
+ type JsonApiResourcePatch = {
370
+ type: string;
371
+ id: string;
372
+ attributes?: Record<string, Value>;
373
+ relationships?: Record<string, ChangedRelationshipData>;
374
+ } | {
375
+ type: string;
376
+ id: null;
377
+ lid: string;
378
+ attributes?: Record<string, Value>;
379
+ relationships?: Record<string, ChangedRelationshipData>;
380
+ };
381
+ /**
382
+ * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
383
+ *
384
+ * While this may come as a surprise, they are intended to serialize cache state for more
385
+ * generalized usage. {json:api} has a large variance in acceptable shapes, and only your
386
+ * app can ensure that the body is correctly formatted and contains all necessary data.
387
+ * :::
388
+ *
389
+ * Serializes the current state of a resource or array of resources for use with POST or PUT requests.
390
+ *
391
+ * @public
392
+ * @param cache - the cache to serialize the resource(s) from
393
+ * @param identifiers - the resource(s) to serialize
394
+ * @return an object with a `data` property containing the serialized resource(s)
395
+ */
396
+ declare function serializeResources(cache: Cache, identifiers: ResourceKey): {
397
+ /**
398
+ * The serialized resource.
399
+ */
400
+ data: ResourceObject;
401
+ };
402
+ declare function serializeResources(cache: Cache, identifiers: ResourceKey[]): {
403
+ /**
404
+ * The serialized resources.
405
+ */
406
+ data: ResourceObject[];
407
+ };
408
+ /**
409
+ * :::warning ⚠️ **This util often won't produce the necessary body for a {json:api} request**
410
+ *
411
+ * While this may come as a surprise, they are intended to serialize cache state for more
412
+ * generalized usage. {json:api} has a large variance in acceptable shapes, and only your
413
+ * app can ensure that the body is correctly formatted and contains all necessary data.
414
+ * :::
415
+ *
416
+ * Serializes changes to a resource. Useful for use with building bodies for PATCH requests.
417
+ *
418
+ * Only attributes which are changed are serialized.
419
+ * Only relationships which are changed are serialized.
420
+ *
421
+ * Collection relationships serialize the collection as a whole.
422
+ *
423
+ * If you would like to serialize updates to a collection more granularly
424
+ * (for instance, as operations) request the diff from the store and
425
+ * serialize as desired:
426
+ *
427
+ * ```ts
428
+ * const relationshipDiffMap = cache.changedRelationships(identifier);
429
+ * ```
430
+ *
431
+ * @public
432
+ * @param cache - the cache to serialize the resource's changes from
433
+ * @param identifier - the resource whose changes should be serialized
434
+ * @return an object with a `data` property containing the serialized resource patch
435
+ */
436
+ declare function serializePatch(cache: Cache, identifier: ResourceKey): {
437
+ /**
438
+ * The serialized resource patch.
439
+ */
440
+ data: JsonApiResourcePatch;
441
+ };
442
+ //#endregion
443
+ //#region src/-private/json-api/-utils.d.ts
444
+ interface JSONAPIConfig extends BuildURLConfig {
445
+ profiles?: {
446
+ pagination?: string;
447
+ [key: string]: string | undefined;
448
+ };
449
+ extensions?: {
450
+ atomic?: string;
451
+ [key: string]: string | undefined;
452
+ };
453
+ }
454
+ /**
455
+ * Allows setting extensions and profiles to be used in the `Accept` header.
456
+ *
457
+ * Extensions and profiles are keyed by their namespace with the value being
458
+ * their URI.
459
+ *
460
+ * Example:
461
+ *
462
+ * ```ts
463
+ * setBuildURLConfig({
464
+ * extensions: {
465
+ * atomic: 'https://jsonapi.org/ext/atomic'
466
+ * },
467
+ * profiles: {
468
+ * pagination: 'https://jsonapi.org/profiles/ethanresnick/cursor-pagination'
469
+ * }
470
+ * });
471
+ * ```
472
+ *
473
+ * This also sets the global configuration for `buildBaseURL`
474
+ * for host and namespace values for the global coniguration
475
+ * done via `import { setBuildURLConfig } from '@warp-drive/utilities';`
476
+ *
477
+ * These values may still be overridden by passing
478
+ * them to buildBaseURL directly.
479
+ *
480
+ * This method may be called as many times as needed
481
+ *
482
+ * ```ts
483
+ * type BuildURLConfig = {
484
+ * host: string;
485
+ * namespace: string'
486
+ * }
487
+ * ```
488
+ *
489
+ * @public
490
+ * @param {BuildURLConfig} config
491
+ * @return {void}
492
+ */
493
+ declare function setBuildURLConfig(config: JSONAPIConfig): void;
494
+ //#endregion
495
+ export { createRecord, deleteRecord, findRecord, postQuery, query, serializePatch, serializeResources, setBuildURLConfig, updateRecord };
496
+ //# sourceMappingURL=json-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-api.d.ts","names":[],"sources":["../src/-private/json-api/find-record.ts","../src/-private/json-api/query.ts","../src/-private/json-api/save-record.ts","../src/-private/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