@warp-drive/utilities 5.10.0-alpha.12 → 5.10.0-alpha.13
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 +9 -0
- package/cjs-dist/string.cjs +19 -0
- package/cjs-dist/string.cjs.map +1 -1
- package/dist/active-record.d.ts +21 -0
- package/dist/active-record.d.ts.map +1 -1
- package/dist/active-record.js +13 -1
- package/dist/active-record.js.map +1 -1
- package/dist/derivations.d.ts +2 -0
- package/dist/derivations.d.ts.map +1 -1
- package/dist/derivations.js +6 -0
- package/dist/derivations.js.map +1 -1
- package/dist/handlers.d.ts +15 -0
- package/dist/handlers.d.ts.map +1 -1
- package/dist/handlers.js +15 -0
- package/dist/handlers.js.map +1 -1
- package/dist/{index-D6QIwzqm.d.ts → index-Ds06tKwC.d.ts} +39 -1
- package/dist/index-Ds06tKwC.d.ts.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -1
- package/dist/json-api.d.ts +36 -1
- package/dist/json-api.d.ts.map +1 -1
- package/dist/json-api.js +23 -1
- package/dist/json-api.js.map +1 -1
- package/dist/rest.d.ts +20 -0
- package/dist/rest.d.ts.map +1 -1
- package/dist/rest.js +13 -1
- package/dist/rest.js.map +1 -1
- package/dist/{string-CWmAluxh.js → string-BZACNuLp.js} +20 -1
- package/dist/string-BZACNuLp.js.map +1 -0
- package/dist/string.d.ts +19 -0
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +1 -1
- package/dist/unpkg/dev/active-record.js +13 -1
- package/dist/unpkg/dev/active-record.js.map +1 -1
- package/dist/unpkg/dev/derivations.js +6 -0
- package/dist/unpkg/dev/derivations.js.map +1 -1
- package/dist/unpkg/dev/handlers.js +15 -0
- package/dist/unpkg/dev/handlers.js.map +1 -1
- package/dist/unpkg/dev/index.js +39 -0
- package/dist/unpkg/dev/index.js.map +1 -1
- package/dist/unpkg/dev/json-api.js +23 -1
- package/dist/unpkg/dev/json-api.js.map +1 -1
- package/dist/unpkg/dev/rest.js +13 -1
- package/dist/unpkg/dev/rest.js.map +1 -1
- package/dist/unpkg/dev/{string-j4ur-TDs.js → string-I8KHJXV7.js} +20 -1
- package/dist/unpkg/dev/string-I8KHJXV7.js.map +1 -0
- package/dist/unpkg/dev/string.js +1 -1
- package/dist/unpkg/dev-deprecated/active-record.js +13 -1
- package/dist/unpkg/dev-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/dev-deprecated/derivations.js +6 -0
- package/dist/unpkg/dev-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/dev-deprecated/handlers.js +15 -0
- package/dist/unpkg/dev-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/dev-deprecated/index.js +39 -0
- package/dist/unpkg/dev-deprecated/index.js.map +1 -1
- package/dist/unpkg/dev-deprecated/json-api.js +23 -1
- package/dist/unpkg/dev-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/dev-deprecated/rest.js +13 -1
- package/dist/unpkg/dev-deprecated/rest.js.map +1 -1
- package/dist/unpkg/dev-deprecated/{string-j4ur-TDs.js → string-I8KHJXV7.js} +20 -1
- package/dist/unpkg/dev-deprecated/string-I8KHJXV7.js.map +1 -0
- package/dist/unpkg/dev-deprecated/string.js +1 -1
- package/dist/unpkg/prod/active-record.js +13 -1
- package/dist/unpkg/prod/active-record.js.map +1 -1
- package/dist/unpkg/prod/derivations.js +6 -0
- package/dist/unpkg/prod/derivations.js.map +1 -1
- package/dist/unpkg/prod/handlers.js +15 -0
- package/dist/unpkg/prod/handlers.js.map +1 -1
- package/dist/unpkg/prod/index.js +39 -0
- package/dist/unpkg/prod/index.js.map +1 -1
- package/dist/unpkg/prod/json-api.js +23 -1
- package/dist/unpkg/prod/json-api.js.map +1 -1
- package/dist/unpkg/prod/rest.js +13 -1
- package/dist/unpkg/prod/rest.js.map +1 -1
- package/dist/unpkg/prod/string-D8BEYx2W.js +302 -0
- package/dist/unpkg/prod/string-D8BEYx2W.js.map +1 -0
- package/dist/unpkg/prod/string.js +1 -1
- package/dist/unpkg/prod-deprecated/active-record.js +13 -1
- package/dist/unpkg/prod-deprecated/active-record.js.map +1 -1
- package/dist/unpkg/prod-deprecated/derivations.js +6 -0
- package/dist/unpkg/prod-deprecated/derivations.js.map +1 -1
- package/dist/unpkg/prod-deprecated/handlers.js +15 -0
- package/dist/unpkg/prod-deprecated/handlers.js.map +1 -1
- package/dist/unpkg/prod-deprecated/index.js +39 -0
- package/dist/unpkg/prod-deprecated/index.js.map +1 -1
- package/dist/unpkg/prod-deprecated/json-api.js +23 -1
- package/dist/unpkg/prod-deprecated/json-api.js.map +1 -1
- package/dist/unpkg/prod-deprecated/rest.js +13 -1
- package/dist/unpkg/prod-deprecated/rest.js.map +1 -1
- package/dist/unpkg/prod-deprecated/{string-T1ahjLdj.js → string-D8BEYx2W.js} +20 -1
- package/dist/unpkg/prod-deprecated/string-D8BEYx2W.js.map +1 -0
- package/dist/unpkg/prod-deprecated/string.js +1 -1
- package/package.json +6 -6
- package/dist/index-D6QIwzqm.d.ts.map +0 -1
- package/dist/string-CWmAluxh.js.map +0 -1
- package/dist/unpkg/dev/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/dev-deprecated/string-j4ur-TDs.js.map +0 -1
- package/dist/unpkg/prod/string-T1ahjLdj.js +0 -283
- package/dist/unpkg/prod/string-T1ahjLdj.js.map +0 -1
- package/dist/unpkg/prod-deprecated/string-T1ahjLdj.js.map +0 -1
package/dist/index.js.map
CHANGED
|
@@ -1 +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","sortedValue","toSorted","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 * The `params` given are never mutated: neither the object itself nor any array\n * value it holds is reordered or replaced, so passing state that is also\n * rendered (a tracked array of filter values, for instance) is safe.\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 // shallow copy so that normalizing `include` below does not write back onto\n // the caller's object. Array values are still shared with the caller, so\n // everything downstream must sort copies rather than sorting in place.\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? Object.assign({}, 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 const sortedValue = value.toSorted();\n switch (opts.arrayFormat) {\n case 'indices':\n sortedValue.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n sortedValue.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n sortedValue.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, sortedValue.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 * The `params` given are never mutated: neither the object itself nor any array\n * value it holds is reordered or replaced, so passing state that is also\n * rendered (a tracked array of filter values, for instance) is safe.\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;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,iBAAiBT,OAAO,CAACY,eAAeX,KAAK;EAEjD;CACF,CAAC;CAGH,IAAI,aAAaQ,kBACfA,iBAAiBd,UAAUD,cAAce,iBAAiBd,OAA4B;CAIxFmB,AADmBvC,OAAOwC,KAAKN,gBAAgB,CAAC,CAACO,KACjDF,CAAU,CAACJ,SAASV,QAAQ;EAC1B,MAAMC,QAAQQ,iBAAiBT;EAC/B,IAAIvB,MAAMC,QAAQuB,KAAK,GAAG;GACxB,MAAMgB,cAAchB,MAAMiB,SAAS;GACnC,QAAQb,KAAKZ,aAAb;IACE,KAAK;KACHwB,YAAYP,SAASS,GAAGvC,MAAM;MAC5B4B,UAAUY,OAAO,GAAGpB,IAAG,GAAIpB,EAAC,IAAKK,OAAOkC,CAAC,CAAC;KAC5C,CAAC;KACD;IACF,KAAK;KACHF,YAAYP,SAASS,MAAM;MACzBX,UAAUY,OAAO,GAAGpB,IAAG,KAAMf,OAAOkC,CAAC,CAAC;KACxC,CAAC;KACD;IACF,KAAK;KACHF,YAAYP,SAASS,MAAM;MACzBX,UAAUY,OAAOpB,KAAKf,OAAOkC,CAAC,CAAC;KACjC,CAAC;KACD;IAEF;KACEX,UAAUY,OAAOpB,KAAKiB,YAAY/B,KAAK,GAAG,CAAC;KAC3C;GACJ;EACF,OACEsB,UAAUY,OAAOpB,KAAKf,OAAOgB,KAAK,CAAC;CAEvC,CAAC;CAED,OAAOO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgBa,iBAAiBjB,QAA2BzC,SAAmD;CAC7G,OAAOwC,gBAAgBC,QAAQzC,OAAO,CAAC,CAAC2D,SAAS;AACnD"}
|
|
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","sortedValue","toSorted","v","append","buildQueryParams","toString"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @summary Helpers for building request URLs and sorted query strings, with a configurable global host and namespace.\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 * @summary The global `host` and `namespace` that `buildBaseURL` prefixes onto URLs when a call does not pass its own.\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 * The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)\n * guide sets these defaults through the `@warp-drive/utilities/json-api` version of this function,\n * which also sets this global configuration.\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 * @summary Sets the app-wide default `host` and `namespace` used by `buildBaseURL` and the request builders.\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 * @summary Options passed to `buildBaseURL` to build the URL for fetching one resource by type and id.\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 * @summary Options passed to `buildBaseURL` to build the URL for querying a collection of one resource type.\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 * @summary Options passed to `buildBaseURL` to build the URL for fetching several resources, pathed by the first\n * identifier's type.\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 * @summary Options passed to `buildBaseURL` to build the URL for a record's has-many relationship, ending in the\n * field name.\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 * @summary Options passed to `buildBaseURL` to build the URL for a record's belongs-to relationship, ending in the\n * field name.\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 * @summary Options passed to `buildBaseURL` to build the collection URL a new record of a given type is saved to.\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 * @summary Options passed to `buildBaseURL` to build the URL for saving changes to an existing record by type and id.\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 * @summary Options passed to `buildBaseURL` to build the URL for deleting an existing record by type and id.\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 * @summary Options passed to `buildBaseURL` to build a URL from an explicit `resourcePath` with no request `op`.\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 * @summary Any of the option shapes `buildBaseURL` accepts, one per request `op` plus a generic `resourcePath` form.\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 * See the [Builders](/guides/the-manual/requests/builders) guide for writing your own request\n * builders.\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 * @summary Joins host, namespace, resource path, id, and relationship field into a request URL without query params.\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 * See [Cache Keys for Requests](/guides/the-manual/requests/builders#cache-keys-for-requests) for\n * why builders need stable query params.\n *\n * @summary Returns a copy of an object without keys whose values are `undefined`, `null`, empty strings, or empty\n * arrays.\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 * See [Cache Keys for Requests](/guides/the-manual/requests/builders#cache-keys-for-requests) for\n * why builders need stable query params.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * The `params` given are never mutated: neither the object itself nor any array\n * value it holds is reordered or replaced, so passing state that is also\n * rendered (a tracked array of filter values, for instance) is safe.\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 * @summary Builds a `URLSearchParams` with keys and array values sorted, so equivalent queries produce identical\n * params.\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 // shallow copy so that normalizing `include` below does not write back onto\n // the caller's object. Array values are still shared with the caller, so\n // everything downstream must sort copies rather than sorting in place.\n const dictionaryParams: Record<string, Serializable> = paramsIsObject ? Object.assign({}, 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 const sortedValue = value.toSorted();\n switch (opts.arrayFormat) {\n case 'indices':\n sortedValue.forEach((v, i) => {\n urlParams.append(`${key}[${i}]`, String(v));\n });\n return;\n case 'bracket':\n sortedValue.forEach((v) => {\n urlParams.append(`${key}[]`, String(v));\n });\n return;\n case 'repeat':\n sortedValue.forEach((v) => {\n urlParams.append(key, String(v));\n });\n return;\n case 'comma':\n default:\n urlParams.append(key, sortedValue.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 * See [Cache Keys for Requests](/guides/the-manual/requests/builders#cache-keys-for-requests) for\n * why builders need stable query params.\n *\n * Treats `included` specially, splicing it into an array if it is a string and sorting the array.\n *\n * The `params` given are never mutated: neither the object itself nor any array\n * value it holds is reordered or replaced, so passing state that is also\n * rendered (a tracked array of filter values, for instance) is safe.\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 * @summary Serializes query params into a string with keys and array values sorted, so equivalent queries share one\n * URL.\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":";;;;;;;;;;;;;;;;AAgCA,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"./index-Ds06tKwC.js";
|
|
2
2
|
import { ReactiveDataDocument } from "@warp-drive/core/reactive";
|
|
3
3
|
import { TypeFromInstance, TypedRecordInstance } from "@warp-drive/core/types/record";
|
|
4
4
|
import { ConstrainedRequestOptions, CreateRequestOptions, DeleteRequestOptions, FindRecordOptions, FindRecordRequestOptions, PostQueryRequestOptions, QueryRequestOptions, RemotelyAccessibleIdentifier, UpdateRequestOptions } from "@warp-drive/core/types/request";
|
|
@@ -13,6 +13,9 @@ import { Value } from "@warp-drive/core/types/json/raw";
|
|
|
13
13
|
* Builds request options to fetch a single resource by a known id or identifier
|
|
14
14
|
* configured for the url and header expectations of most JSON:API APIs.
|
|
15
15
|
*
|
|
16
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
17
|
+
* when to use one.
|
|
18
|
+
*
|
|
16
19
|
* :::tabs
|
|
17
20
|
*
|
|
18
21
|
* == Basic Usage
|
|
@@ -82,6 +85,7 @@ import { Value } from "@warp-drive/core/types/json/raw";
|
|
|
82
85
|
* );
|
|
83
86
|
* ```
|
|
84
87
|
*
|
|
88
|
+
* @summary Builds a JSON:API `GET` request for one resource by type and id, with optional `include`.
|
|
85
89
|
* @public
|
|
86
90
|
*/
|
|
87
91
|
export declare function findRecord<T, M extends Meta | undefined = Meta | undefined, E extends object = ApiError>(identifier: RemotelyAccessibleIdentifier<TypeFromInstance<T>>, options?: FindRecordOptions): FindRecordRequestOptions<ReactiveDataDocument<T, M, E>, T>;
|
|
@@ -94,6 +98,9 @@ export declare function findRecord(type: string, id: string, options?: FindRecor
|
|
|
94
98
|
* Builds request options to query for resources, usually by a primary
|
|
95
99
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
96
100
|
*
|
|
101
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
102
|
+
* when to use one.
|
|
103
|
+
*
|
|
97
104
|
* The key difference between this and `postQuery` is that this method will send the query
|
|
98
105
|
* as query params in the url of a "GET" request instead of as the JSON body of a "POST"
|
|
99
106
|
* request.
|
|
@@ -136,6 +143,7 @@ export declare function findRecord(type: string, id: string, options?: FindRecor
|
|
|
136
143
|
* const data = await store.request(options);
|
|
137
144
|
* ```
|
|
138
145
|
*
|
|
146
|
+
* @summary Builds a JSON:API `GET` request that queries a resource type, sending the query as URL query params.
|
|
139
147
|
* @public
|
|
140
148
|
* @badge Builder
|
|
141
149
|
*/
|
|
@@ -145,6 +153,9 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
145
153
|
* Builds request options to query for resources, usually by a primary
|
|
146
154
|
* type, configured for the url and header expectations of most JSON:API APIs.
|
|
147
155
|
*
|
|
156
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
157
|
+
* when to use one.
|
|
158
|
+
*
|
|
148
159
|
* The key difference between this and `query` is that this method will send the query
|
|
149
160
|
* as the JSON body of a "POST" request instead of as query params in the url of a "GET"
|
|
150
161
|
* request.
|
|
@@ -180,6 +191,8 @@ export declare function query(type: string, query?: QueryParamsSource, options?:
|
|
|
180
191
|
* const data = await store.request(options);
|
|
181
192
|
* ```
|
|
182
193
|
*
|
|
194
|
+
* @summary Builds a JSON:API `POST` request that sends a query as the JSON body, cached under a key built from the
|
|
195
|
+
* query params.
|
|
183
196
|
* @public
|
|
184
197
|
* @param type - the name of the resource type to query
|
|
185
198
|
* @param query - the query params to send with the request
|
|
@@ -198,6 +211,9 @@ export declare function postQuery(type: string, query?: QueryParamsSource, optio
|
|
|
198
211
|
* Builds request options to delete record for resources,
|
|
199
212
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
200
213
|
*
|
|
214
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
215
|
+
* when to use one.
|
|
216
|
+
*
|
|
201
217
|
* **Basic Usage**
|
|
202
218
|
*
|
|
203
219
|
* ```ts
|
|
@@ -239,6 +255,7 @@ export declare function postQuery(type: string, query?: QueryParamsSource, optio
|
|
|
239
255
|
* const data = await store.request(options);
|
|
240
256
|
* ```
|
|
241
257
|
*
|
|
258
|
+
* @summary Builds a JSON:API `DELETE` request that persists deletion of an existing record.
|
|
242
259
|
* @public
|
|
243
260
|
* @param record
|
|
244
261
|
* @param options
|
|
@@ -254,6 +271,9 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
|
|
|
254
271
|
* Builds request options to create new record for resources,
|
|
255
272
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
256
273
|
*
|
|
274
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
275
|
+
* when to use one.
|
|
276
|
+
*
|
|
257
277
|
* **Basic Usage**
|
|
258
278
|
*
|
|
259
279
|
* ```ts
|
|
@@ -295,6 +315,7 @@ export declare function deleteRecord(record: unknown, options?: ConstrainedReque
|
|
|
295
315
|
* const data = await store.request(options);
|
|
296
316
|
* ```
|
|
297
317
|
*
|
|
318
|
+
* @summary Builds a JSON:API `POST` request for saving a new record; the app must set the request body itself.
|
|
298
319
|
* @public
|
|
299
320
|
* @param record
|
|
300
321
|
* @param options
|
|
@@ -310,6 +331,9 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
|
|
|
310
331
|
* Builds request options to update existing record for resources,
|
|
311
332
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
312
333
|
*
|
|
334
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
335
|
+
* when to use one.
|
|
336
|
+
*
|
|
313
337
|
* **Example Usage**
|
|
314
338
|
*
|
|
315
339
|
* ```ts
|
|
@@ -354,6 +378,8 @@ export declare function createRecord(record: unknown, options?: ConstrainedReque
|
|
|
354
378
|
* const data = await store.request(options);
|
|
355
379
|
* ```
|
|
356
380
|
*
|
|
381
|
+
* @summary Builds a JSON:API `PUT` (or `PATCH`) request for saving an existing record; the app must set the request
|
|
382
|
+
* body itself.
|
|
357
383
|
* @public
|
|
358
384
|
* @param record
|
|
359
385
|
* @param options
|
|
@@ -389,6 +415,8 @@ type JsonApiResourcePatch = {
|
|
|
389
415
|
*
|
|
390
416
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
391
417
|
*
|
|
418
|
+
* @summary Copies the cached state of one or more resources into a JSON:API-style `{ data }` object, a starting point
|
|
419
|
+
* for request bodies.
|
|
392
420
|
* @public
|
|
393
421
|
* @param cache - the cache to serialize the resource(s) from
|
|
394
422
|
* @param identifiers - the resource(s) to serialize
|
|
@@ -429,6 +457,8 @@ export declare function serializeResources(cache: Cache, identifiers: ResourceKe
|
|
|
429
457
|
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
430
458
|
* ```
|
|
431
459
|
*
|
|
460
|
+
* @summary Serializes only a resource's changed attributes and relationships from the cache into a JSON:API-style
|
|
461
|
+
* `{ data }` patch.
|
|
432
462
|
* @public
|
|
433
463
|
* @param cache - the cache to serialize the resource's changes from
|
|
434
464
|
* @param identifier - the resource whose changes should be serialized
|
|
@@ -458,6 +488,9 @@ interface JSONAPIConfig extends BuildURLConfig {
|
|
|
458
488
|
* Extensions and profiles are keyed by their namespace with the value being
|
|
459
489
|
* their URI.
|
|
460
490
|
*
|
|
491
|
+
* The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)
|
|
492
|
+
* guide uses it to configure a host, a namespace and a pagination profile.
|
|
493
|
+
*
|
|
461
494
|
* Example:
|
|
462
495
|
*
|
|
463
496
|
* ```ts
|
|
@@ -487,6 +520,8 @@ interface JSONAPIConfig extends BuildURLConfig {
|
|
|
487
520
|
* }
|
|
488
521
|
* ```
|
|
489
522
|
*
|
|
523
|
+
* @summary Sets the JSON:API extensions and profiles sent in the `Accept` header, plus the global URL host and
|
|
524
|
+
* namespace.
|
|
490
525
|
* @public
|
|
491
526
|
* @param {BuildURLConfig} config
|
|
492
527
|
* @return {void}
|
package/dist/json-api.d.ts.map
CHANGED
|
@@ -1 +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/json-api/serialize.ts","../src/-private/json-api/-utils.ts"],"mappings":"
|
|
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/json-api/serialize.ts","../src/-private/json-api/-utils.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8FgB,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC9F,YAAY,6BAA6B,iBAAiB,KAC1D,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WACd,YAAY,8BACZ,UAAU,oBACT;wBACa,WAAW,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC9F,MAAM,iBAAiB,IACvB,YACA,UAAU,oBACT,yBAAyB,qBAAqB,GAAG,GAAG,IAAI;wBAC3C,WAAW,cAAc,YAAY,UAAU,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCtCnE,MACd,UAAU,qBACV,UAAU,mBAAmB,kBAC7B,mBAAmB,UAEnB,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,oBAAoB,qBAAqB,KAAK,GAAG;wBACpC,MACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+Ea,UAAU,GAAG,UAAU,mBAAmB,kBAAkB,mBAAmB,UAC7F,MAAM,iBAAiB,IACvB,QAAQ,mBACR,UAAU,4BACT,wBAAwB,qBAAqB,KAAK,GAAG;wBACxC,UACd,cACA,QAAQ,mBACR,UAAU,4BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBCpFa,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAwFpE,aAAa,GAAG,QAAQ,GAAG,UAAU,4BAA4B,qBAAqB;wBACtF,aAAa,iBAAiB,UAAU,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2FpE,aACd,UAAU,qBACV,WAAW,sBAAsB,GACjC,UAAU,mBAAmB,kBAC7B,mBAAmB,UAEnB,QAAQ,GACR,UAAU;EAA8B;IACvC,qBAAqB,qBAAqB,IAAI,GAAG,IAAI;wBACxC,aACd,iBACA,UAAU;EAA8B;IACvC;;;KChRE,0BAA0B;KAEnB;EAEN;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;EAG/B;EACA;EACA;EACA,aAAa,eAAe;EAC5B,gBAAgB,eAAe;;;;;;;;;;;;;;;;;;;wBAoBrB,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;wBAEQ,mBACd,OAAO,OACP,aAAa;;;;EAKb,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuGQ,eACd,OAAO,OACP,YAAY;;;;EAMZ,MAAM;;;;UCnKS,sBAAsB;EACrC;IACE;;;EAGF;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAsDY,kBAAkB,QAAQ"}
|
package/dist/json-api.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { buildBaseURL, buildQueryParams, setBuildURLConfig as setBuildURLConfig$1 } from "./index.js";
|
|
2
|
-
import { s as pluralize } from "./string-
|
|
2
|
+
import { s as pluralize } from "./string-BZACNuLp.js";
|
|
3
3
|
import { n as extractCacheOptions, t as copyForwardUrlOptions } from "./builder-utils-BkXwUT0x.js";
|
|
4
4
|
import { getGlobalConfig, macroCondition } from "@embroider/macros";
|
|
5
5
|
import { recordIdentifierFor } from "@warp-drive/core";
|
|
@@ -18,6 +18,9 @@ let ACCEPT_HEADER_VALUE = "application/vnd.api+json";
|
|
|
18
18
|
* Extensions and profiles are keyed by their namespace with the value being
|
|
19
19
|
* their URI.
|
|
20
20
|
*
|
|
21
|
+
* The [Basic Usage](/guides/the-manual/cookbook/basic-usage#step-2-configure-some-request-defaults)
|
|
22
|
+
* guide uses it to configure a host, a namespace and a pagination profile.
|
|
23
|
+
*
|
|
21
24
|
* Example:
|
|
22
25
|
*
|
|
23
26
|
* ```ts
|
|
@@ -47,6 +50,8 @@ let ACCEPT_HEADER_VALUE = "application/vnd.api+json";
|
|
|
47
50
|
* }
|
|
48
51
|
* ```
|
|
49
52
|
*
|
|
53
|
+
* @summary Sets the JSON:API extensions and profiles sent in the `Accept` header, plus the global URL host and
|
|
54
|
+
* namespace.
|
|
50
55
|
* @public
|
|
51
56
|
* @param {BuildURLConfig} config
|
|
52
57
|
* @return {void}
|
|
@@ -155,6 +160,9 @@ function isExisting(identifier) {
|
|
|
155
160
|
* Builds request options to delete record for resources,
|
|
156
161
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
157
162
|
*
|
|
163
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
164
|
+
* when to use one.
|
|
165
|
+
*
|
|
158
166
|
* **Basic Usage**
|
|
159
167
|
*
|
|
160
168
|
* ```ts
|
|
@@ -196,6 +204,7 @@ function isExisting(identifier) {
|
|
|
196
204
|
* const data = await store.request(options);
|
|
197
205
|
* ```
|
|
198
206
|
*
|
|
207
|
+
* @summary Builds a JSON:API `DELETE` request that persists deletion of an existing record.
|
|
199
208
|
* @public
|
|
200
209
|
* @param record
|
|
201
210
|
* @param options
|
|
@@ -235,6 +244,9 @@ function deleteRecord(record, options = {}) {
|
|
|
235
244
|
* Builds request options to create new record for resources,
|
|
236
245
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
237
246
|
*
|
|
247
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
248
|
+
* when to use one.
|
|
249
|
+
*
|
|
238
250
|
* **Basic Usage**
|
|
239
251
|
*
|
|
240
252
|
* ```ts
|
|
@@ -276,6 +288,7 @@ function deleteRecord(record, options = {}) {
|
|
|
276
288
|
* const data = await store.request(options);
|
|
277
289
|
* ```
|
|
278
290
|
*
|
|
291
|
+
* @summary Builds a JSON:API `POST` request for saving a new record; the app must set the request body itself.
|
|
279
292
|
* @public
|
|
280
293
|
* @param record
|
|
281
294
|
* @param options
|
|
@@ -312,6 +325,9 @@ function createRecord(record, options = {}) {
|
|
|
312
325
|
* Builds request options to update existing record for resources,
|
|
313
326
|
* configured for the url, method and header expectations of most JSON:API APIs.
|
|
314
327
|
*
|
|
328
|
+
* See the [Builders](/guides/the-manual/requests/builders) guide for what request builders do and
|
|
329
|
+
* when to use one.
|
|
330
|
+
*
|
|
315
331
|
* **Example Usage**
|
|
316
332
|
*
|
|
317
333
|
* ```ts
|
|
@@ -356,6 +372,8 @@ function createRecord(record, options = {}) {
|
|
|
356
372
|
* const data = await store.request(options);
|
|
357
373
|
* ```
|
|
358
374
|
*
|
|
375
|
+
* @summary Builds a JSON:API `PUT` (or `PATCH`) request for saving an existing record; the app must set the request
|
|
376
|
+
* body itself.
|
|
359
377
|
* @public
|
|
360
378
|
* @param record
|
|
361
379
|
* @param options
|
|
@@ -399,6 +417,8 @@ function updateRecord(record, options = {}) {
|
|
|
399
417
|
*
|
|
400
418
|
* Serializes the current state of a resource or array of resources for use with POST or PUT requests.
|
|
401
419
|
*
|
|
420
|
+
* @summary Copies the cached state of one or more resources into a JSON:API-style `{ data }` object, a starting point
|
|
421
|
+
* for request bodies.
|
|
402
422
|
* @public
|
|
403
423
|
* @param cache - the cache to serialize the resource(s) from
|
|
404
424
|
* @param identifiers - the resource(s) to serialize
|
|
@@ -461,6 +481,8 @@ function _serializeResource(cache, identifier) {
|
|
|
461
481
|
* const relationshipDiffMap = cache.changedRelationships(identifier);
|
|
462
482
|
* ```
|
|
463
483
|
*
|
|
484
|
+
* @summary Serializes only a resource's changed attributes and relationships from the cache into a JSON:API-style
|
|
485
|
+
* `{ data }` patch.
|
|
464
486
|
* @public
|
|
465
487
|
* @param cache - the cache to serialize the resource's changes from
|
|
466
488
|
* @param identifier - the resource whose changes should be serialized
|