@ember-data-mirror/request-utils 5.6.0-alpha.0 → 5.6.0-alpha.11

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/addon-main.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const { addonShim } = require('@warp-drive-mirror/build-config/addon-shim.cjs');
3
+ const { addonShim } = require('@warp-drive-mirror/core/addon-shim.cjs');
4
4
 
5
5
  module.exports = addonShim(__dirname);
@@ -1,7 +1,7 @@
1
1
  import { deprecate } from '@ember/debug';
2
2
  import { macroCondition, getGlobalConfig, dependencySatisfies, importSync } from '@embroider/macros';
3
- import { f as defaultRules, b as plural, a as singular, i as irregular, u as uncountable } from "./inflect-CwI_k2it.js";
4
- import "./transform-1PDozfHr.js";
3
+ import { InflectionRuleDefaults } from '@warp-drive-mirror/utilities/-private';
4
+ import { plural, singular, irregular, uncountable } from '@warp-drive-mirror/utilities/string';
5
5
  if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_EMBER_INFLECTOR)) {
6
6
  if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {
7
7
  const Inflector = importSync('ember-inflector').default;
@@ -25,22 +25,22 @@ if (macroCondition(getGlobalConfig().WarpDriveMirror.deprecations.DEPRECATE_EMBE
25
25
  // is default via our own list.
26
26
  const defaultPluralKeys = new Set();
27
27
  const defaultSingularKeys = new Set();
28
- defaultRules.plurals.forEach(([regex]) => {
28
+ InflectionRuleDefaults.plurals.forEach(([regex]) => {
29
29
  defaultPluralKeys.add(regex.toString());
30
30
  });
31
- defaultRules.singular.forEach(([regex]) => {
31
+ InflectionRuleDefaults.singular.forEach(([regex]) => {
32
32
  defaultSingularKeys.add(regex.toString());
33
33
  });
34
34
  const {
35
- defaultRules: defaultRules$1
35
+ defaultRules
36
36
  } = Inflector;
37
37
  const {
38
38
  rules
39
39
  } = inflector;
40
40
  const irregularMap = new Map();
41
41
  const toIgnore = new Set();
42
- const uncountableSet = new Set(defaultRules$1.uncountable);
43
- defaultRules$1.irregularPairs.forEach(([single, plur]) => {
42
+ const uncountableSet = new Set(defaultRules.uncountable);
43
+ defaultRules.irregularPairs.forEach(([single, plur]) => {
44
44
  irregularMap.set(single.toLowerCase(), plur);
45
45
  toIgnore.add(plur.toLowerCase());
46
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"deprecation-support.js","sources":["../src/deprecation-support.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';\n\nimport { DEPRECATE_EMBER_INFLECTOR } from '@warp-drive-mirror/build-config/deprecations';\n\nimport { defaultRules as WarpDriveDefaults } from './-private/string/inflections';\nimport { irregular, plural, singular, uncountable } from './string';\n\nif (DEPRECATE_EMBER_INFLECTOR) {\n if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {\n const Inflector = (importSync('ember-inflector') as { default: typeof import('ember-inflector').default }).default;\n const { inflector } = Inflector;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalPlural = inflector.plural;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalSingular = inflector.singular;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalIrregular = inflector.irregular;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalUncountable = inflector.uncountable;\n\n // copy over any already registered rules\n type DefaultRules = {\n plurals: [RegExp, string][];\n singular: [RegExp, string][];\n irregularPairs: [string, string][];\n uncountable: string[];\n };\n type InternalRules = {\n plurals: [RegExp, string][];\n singular: [RegExp, string][];\n\n // [str1, str2] =>\n // { [str1.lower]: str2 }\n // { [str2.lower]: str2 }\n irregular: Record<string, string>;\n\n // [str1, str2] =>\n // { [str2.lower]: str1 }\n // { [str1.lower]: str1 }\n irregularInverse: Record<string, string>;\n\n // lower cased string\n uncountable: Record<string, boolean>;\n };\n\n // ember-inflector mutates the default rules arrays\n // with user supplied rules, so we keep track of what\n // is default via our own list.\n const defaultPluralKeys = new Set<string>();\n const defaultSingularKeys = new Set<string>();\n WarpDriveDefaults.plurals.forEach(([regex]) => {\n defaultPluralKeys.add(regex.toString());\n });\n WarpDriveDefaults.singular.forEach(([regex]) => {\n defaultSingularKeys.add(regex.toString());\n });\n\n const { defaultRules } = Inflector as unknown as { defaultRules: DefaultRules };\n const { rules } = inflector as unknown as { rules: InternalRules };\n\n const irregularMap = new Map<string, string>();\n const toIgnore = new Set<string>();\n const uncountableSet = new Set(defaultRules.uncountable);\n\n defaultRules.irregularPairs.forEach(([single, plur]) => {\n irregularMap.set(single.toLowerCase(), plur);\n toIgnore.add(plur.toLowerCase());\n });\n const irregularLookups = new Map<string, string>();\n Object.keys(rules.irregular).forEach((single) => {\n const plur = rules.irregular[single];\n irregularLookups.set(single, plur);\n });\n\n // load plurals\n rules.plurals.forEach(([regex, replacement]) => {\n if (defaultPluralKeys.has(regex.toString())) {\n return;\n }\n\n plural(regex, replacement);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for pluralization.\\nPlease \\`import { plural } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom pluralization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load singulars\n rules.singular.forEach(([regex, replacement]) => {\n if (defaultSingularKeys.has(regex.toString())) {\n return;\n }\n\n singular(regex, replacement);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for singularization.\\nPlease \\`import { singular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom singularization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load irregulars\n Object.keys(rules.irregular).forEach((single) => {\n const plur = rules.irregular[single];\n const defaultPlur = irregularMap.get(single);\n if (defaultPlur && defaultPlur === plur) {\n return;\n }\n\n if (toIgnore.has(single)) {\n return;\n }\n\n const actualSingle = irregularLookups.get(plur.toLowerCase()) || single;\n toIgnore.add(plur.toLowerCase());\n irregular(actualSingle, plur);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for irregular rules.\\nPlease \\`import { irregular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom irregular rule for use with EmberData for '${actualSingle}' <=> '${plur}'.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load uncountables\n Object.keys(rules.uncountable).forEach((word) => {\n if (uncountableSet.has(word) || rules.uncountable[word] !== true) {\n return;\n }\n\n uncountable(word);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for uncountable rules.\\nPlease \\`import { uncountable } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom uncountable rule for '${word}' for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n inflector.plural = function (...args: Parameters<typeof originalPlural>) {\n plural(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for pluralization.\\nPlease \\`import { plural } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom pluralization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalPlural.apply(inflector, args);\n };\n\n inflector.singular = function (...args: Parameters<typeof originalSingular>) {\n singular(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for singularization.\\nPlease \\`import { singular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom singularization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalSingular.apply(inflector, args);\n };\n\n inflector.irregular = function (...args: Parameters<typeof originalIrregular>) {\n irregular(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for irregular rules.\\nPlease \\`import { irregular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom irregular rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalIrregular.apply(inflector, args);\n };\n\n inflector.uncountable = function (...args: Parameters<typeof originalUncountable>) {\n uncountable(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for uncountable rules.\\nPlease \\`import { uncountable } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom uncountable rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalUncountable.apply(inflector, args);\n };\n }\n}\n"],"names":["macroCondition","getGlobalConfig","WarpDrive","deprecations","DEPRECATE_EMBER_INFLECTOR","dependencySatisfies","Inflector","importSync","default","inflector","originalPlural","plural","originalSingular","singular","originalIrregular","irregular","originalUncountable","uncountable","defaultPluralKeys","Set","defaultSingularKeys","WarpDriveDefaults","plurals","forEach","regex","add","toString","defaultRules","rules","irregularMap","Map","toIgnore","uncountableSet","irregularPairs","single","plur","set","toLowerCase","irregularLookups","Object","keys","replacement","has","deprecate","id","until","for","since","enabled","available","url","defaultPlur","get","actualSingle","word","args","apply"],"mappings":";;;;;AASA,IAAAA,cAAA,CAAAC,eAAA,EAAA,CAAAC,SAAA,CAAAC,YAAA,CAAAC,yBAAA,CAA+B,EAAA;EAC7B,IAAIJ,cAAc,CAACK,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,EAAE;AAC/D,IAAA,MAAMC,SAAS,GAAIC,UAAU,CAAC,iBAAiB,CAAC,CAA2DC,OAAO;IAClH,MAAM;AAAEC,MAAAA;AAAU,KAAC,GAAGH,SAAS;;AAE/B;AACA,IAAA,MAAMI,cAAc,GAAGD,SAAS,CAACE,MAAM;AACvC;AACA,IAAA,MAAMC,gBAAgB,GAAGH,SAAS,CAACI,QAAQ;AAC3C;AACA,IAAA,MAAMC,iBAAiB,GAAGL,SAAS,CAACM,SAAS;AAC7C;AACA,IAAA,MAAMC,mBAAmB,GAAGP,SAAS,CAACQ,WAAW;;AAEjD;;AAyBA;AACA;AACA;AACA,IAAA,MAAMC,iBAAiB,GAAG,IAAIC,GAAG,EAAU;AAC3C,IAAA,MAAMC,mBAAmB,GAAG,IAAID,GAAG,EAAU;IAC7CE,YAAiB,CAACC,OAAO,CAACC,OAAO,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK;MAC7CN,iBAAiB,CAACO,GAAG,CAACD,KAAK,CAACE,QAAQ,EAAE,CAAC;AACzC,KAAC,CAAC;IACFL,YAAiB,CAACR,QAAQ,CAACU,OAAO,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK;MAC9CJ,mBAAmB,CAACK,GAAG,CAACD,KAAK,CAACE,QAAQ,EAAE,CAAC;AAC3C,KAAC,CAAC;IAEF,MAAM;AAAEC,oBAAAA;AAAa,KAAC,GAAGrB,SAAsD;IAC/E,MAAM;AAAEsB,MAAAA;AAAM,KAAC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,IAA4C,EAAE;MACjFtC,WAAW,CAAC,GAAGsC,IAAI,CAAC;AAEpBZ,MAAAA,SAAS,CACP,CAAA,2NAAA,CAA6N,EAC7N,KAAK,EACL;AACEC,QAAAA,EAAE,EAAE,4BAA4B;AAChCC,QAAAA,KAAK,EAAE,OAAO;AACdC,QAAAA,GAAG,EAAE,YAAY;AACjBC,QAAAA,KAAK,EAAE;AACLC,UAAAA,OAAO,EAAE,OAAO;AAChBC,UAAAA,SAAS,EAAE;SACZ;AACDC,QAAAA,GAAG,EAAE;AACP,OACF,CAAC;AAED,MAAA,OAAOlC,mBAAmB,CAACwC,KAAK,CAAC/C,SAAS,EAAE8C,IAAI,CAAC;KAClD;AACH;AACF"}
1
+ {"version":3,"file":"deprecation-support.js","sources":["../src/deprecation-support.ts"],"sourcesContent":["import { deprecate } from '@ember/debug';\n\nimport { dependencySatisfies, importSync, macroCondition } from '@embroider/macros';\n\nimport { DEPRECATE_EMBER_INFLECTOR } from '@warp-drive-mirror/core/build-config/deprecations';\nimport { InflectionRuleDefaults } from '@warp-drive-mirror/utilities/-private';\n\nimport { irregular, plural, singular, uncountable } from './string.ts';\n\nif (DEPRECATE_EMBER_INFLECTOR) {\n if (macroCondition(dependencySatisfies('ember-inflector', '*'))) {\n const Inflector = (importSync('ember-inflector') as { default: typeof import('ember-inflector').default }).default;\n const { inflector } = Inflector;\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalPlural = inflector.plural;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalSingular = inflector.singular;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalIrregular = inflector.irregular;\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const originalUncountable = inflector.uncountable;\n\n // copy over any already registered rules\n type DefaultRules = {\n plurals: [RegExp, string][];\n singular: [RegExp, string][];\n irregularPairs: [string, string][];\n uncountable: string[];\n };\n type InternalRules = {\n plurals: [RegExp, string][];\n singular: [RegExp, string][];\n\n // [str1, str2] =>\n // { [str1.lower]: str2 }\n // { [str2.lower]: str2 }\n irregular: Record<string, string>;\n\n // [str1, str2] =>\n // { [str2.lower]: str1 }\n // { [str1.lower]: str1 }\n irregularInverse: Record<string, string>;\n\n // lower cased string\n uncountable: Record<string, boolean>;\n };\n\n // ember-inflector mutates the default rules arrays\n // with user supplied rules, so we keep track of what\n // is default via our own list.\n const defaultPluralKeys = new Set<string>();\n const defaultSingularKeys = new Set<string>();\n InflectionRuleDefaults.plurals.forEach(([regex]) => {\n defaultPluralKeys.add(regex.toString());\n });\n InflectionRuleDefaults.singular.forEach(([regex]) => {\n defaultSingularKeys.add(regex.toString());\n });\n\n const { defaultRules } = Inflector as unknown as { defaultRules: DefaultRules };\n const { rules } = inflector as unknown as { rules: InternalRules };\n\n const irregularMap = new Map<string, string>();\n const toIgnore = new Set<string>();\n const uncountableSet = new Set(defaultRules.uncountable);\n\n defaultRules.irregularPairs.forEach(([single, plur]) => {\n irregularMap.set(single.toLowerCase(), plur);\n toIgnore.add(plur.toLowerCase());\n });\n const irregularLookups = new Map<string, string>();\n Object.keys(rules.irregular).forEach((single) => {\n const plur = rules.irregular[single];\n irregularLookups.set(single, plur);\n });\n\n // load plurals\n rules.plurals.forEach(([regex, replacement]) => {\n if (defaultPluralKeys.has(regex.toString())) {\n return;\n }\n\n plural(regex, replacement);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for pluralization.\\nPlease \\`import { plural } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom pluralization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load singulars\n rules.singular.forEach(([regex, replacement]) => {\n if (defaultSingularKeys.has(regex.toString())) {\n return;\n }\n\n singular(regex, replacement);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for singularization.\\nPlease \\`import { singular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom singularization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load irregulars\n Object.keys(rules.irregular).forEach((single) => {\n const plur = rules.irregular[single];\n const defaultPlur = irregularMap.get(single);\n if (defaultPlur && defaultPlur === plur) {\n return;\n }\n\n if (toIgnore.has(single)) {\n return;\n }\n\n const actualSingle = irregularLookups.get(plur.toLowerCase()) || single;\n toIgnore.add(plur.toLowerCase());\n irregular(actualSingle, plur);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for irregular rules.\\nPlease \\`import { irregular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom irregular rule for use with EmberData for '${actualSingle}' <=> '${plur}'.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n // load uncountables\n Object.keys(rules.uncountable).forEach((word) => {\n if (uncountableSet.has(word) || rules.uncountable[word] !== true) {\n return;\n }\n\n uncountable(word);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for uncountable rules.\\nPlease \\`import { uncountable } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom uncountable rule for '${word}' for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n });\n\n inflector.plural = function (...args: Parameters<typeof originalPlural>) {\n plural(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for pluralization.\\nPlease \\`import { plural } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom pluralization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalPlural.apply(inflector, args);\n };\n\n inflector.singular = function (...args: Parameters<typeof originalSingular>) {\n singular(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for singularization.\\nPlease \\`import { singular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom singularization rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalSingular.apply(inflector, args);\n };\n\n inflector.irregular = function (...args: Parameters<typeof originalIrregular>) {\n irregular(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for irregular rules.\\nPlease \\`import { irregular } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom irregular rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalIrregular.apply(inflector, args);\n };\n\n inflector.uncountable = function (...args: Parameters<typeof originalUncountable>) {\n uncountable(...args);\n\n deprecate(\n `WarpDrive/EmberData no longer uses ember-inflector for uncountable rules.\\nPlease \\`import { uncountable } from '@ember-data-mirror/request-utils/string';\\` instead to register a custom uncountable rule for use with EmberData.`,\n false,\n {\n id: 'warp-drive.ember-inflector',\n until: '6.0.0',\n for: 'warp-drive',\n since: {\n enabled: '5.3.4',\n available: '4.13',\n },\n url: 'https://deprecations.emberjs.com/id/warp-drive.ember-inflector',\n }\n );\n\n return originalUncountable.apply(inflector, args);\n };\n }\n}\n"],"names":["macroCondition","getGlobalConfig","WarpDrive","deprecations","DEPRECATE_EMBER_INFLECTOR","dependencySatisfies","Inflector","importSync","default","inflector","originalPlural","plural","originalSingular","singular","originalIrregular","irregular","originalUncountable","uncountable","defaultPluralKeys","Set","defaultSingularKeys","InflectionRuleDefaults","plurals","forEach","regex","add","toString","defaultRules","rules","irregularMap","Map","toIgnore","uncountableSet","irregularPairs","single","plur","set","toLowerCase","irregularLookups","Object","keys","replacement","has","deprecate","id","until","for","since","enabled","available","url","defaultPlur","get","actualSingle","word","args","apply"],"mappings":";;;;;AASA,IAAAA,cAAA,CAAAC,eAAA,EAAA,CAAAC,SAAA,CAAAC,YAAA,CAAAC,yBAAA,CAA+B,EAAA;EAC7B,IAAIJ,cAAc,CAACK,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC,EAAE;AAC/D,IAAA,MAAMC,SAAS,GAAIC,UAAU,CAAC,iBAAiB,CAAC,CAA2DC,OAAO;IAClH,MAAM;AAAEC,MAAAA;AAAU,KAAC,GAAGH,SAAS;;AAE/B;AACA,IAAA,MAAMI,cAAc,GAAGD,SAAS,CAACE,MAAM;AACvC;AACA,IAAA,MAAMC,gBAAgB,GAAGH,SAAS,CAACI,QAAQ;AAC3C;AACA,IAAA,MAAMC,iBAAiB,GAAGL,SAAS,CAACM,SAAS;AAC7C;AACA,IAAA,MAAMC,mBAAmB,GAAGP,SAAS,CAACQ,WAAW;;AAEjD;;AAyBA;AACA;AACA;AACA,IAAA,MAAMC,iBAAiB,GAAG,IAAIC,GAAG,EAAU;AAC3C,IAAA,MAAMC,mBAAmB,GAAG,IAAID,GAAG,EAAU;IAC7CE,sBAAsB,CAACC,OAAO,CAACC,OAAO,CAAC,CAAC,CAACC,KAAK,CAAC,KAAK;MAClDN,iBAAiB,CAACO,GAAG,CAACD,KAAK,CAACE,QAAQ,EAAE,CAAC;AACzC,KAAC,CAAC;IACFL,sBAAsB,CAACR,QAAQ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A,OAAO,EAAE,OAAO;AAChBC,UAAAA,SAAS,EAAE;SACZ;AACDC,QAAAA,GAAG,EAAE;AACP,OACF,CAAC;AAED,MAAA,OAAOpC,iBAAiB,CAAC0C,KAAK,CAAC/C,SAAS,EAAE8C,IAAI,CAAC;KAChD;AAED9C,IAAAA,SAAS,CAACQ,WAAW,GAAG,UAAU,GAAGsC,IAA4C,EAAE;MACjFtC,WAAW,CAAC,GAAGsC,IAAI,CAAC;AAEpBZ,MAAAA,SAAS,CACP,CAAA,2NAAA,CAA6N,EAC7N,KAAK,EACL;AACEC,QAAAA,EAAE,EAAE,4BAA4B;AAChCC,QAAAA,KAAK,EAAE,OAAO;AACdC,QAAAA,GAAG,EAAE,YAAY;AACjBC,QAAAA,KAAK,EAAE;AACLC,UAAAA,OAAO,EAAE,OAAO;AAChBC,UAAAA,SAAS,EAAE;SACZ;AACDC,QAAAA,GAAG,EAAE;AACP,OACF,CAAC;AAED,MAAA,OAAOlC,mBAAmB,CAACwC,KAAK,CAAC/C,SAAS,EAAE8C,IAAI,CAAC;KAClD;AACH;AACF"}
package/dist/handlers.js CHANGED
@@ -1,147 +1 @@
1
- /**
2
- * @module @ember-data-mirror/request-utils/handlers
3
- */
4
-
5
- function isCompressibleMethod(method) {
6
- return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';
7
- }
8
- const SupportsRequestStreams = (() => {
9
- let duplexAccessed = false;
10
- const hasContentType = new Request('', {
11
- body: new ReadableStream(),
12
- method: 'POST',
13
- // @ts-expect-error untyped
14
- get duplex() {
15
- duplexAccessed = true;
16
- return 'half';
17
- }
18
- }).headers.has('Content-Type');
19
- return duplexAccessed && !hasContentType;
20
- })();
21
-
22
- /**
23
- * Options for configuring the AutoCompress handler.
24
- *
25
- * @typedoc
26
- */
27
-
28
- const DEFAULT_CONSTRAINTS = {
29
- Blob: 1000,
30
- ArrayBuffer: 1000,
31
- TypedArray: 1000,
32
- DataView: 1000,
33
- String: 1000
34
- };
35
- const TypedArray = Object.getPrototypeOf(Uint8Array.prototype);
36
-
37
- /**
38
- * A request handler that automatically compresses the request body
39
- * if the request body is a string, array buffer, blob, or form data.
40
- *
41
- * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)
42
- *
43
- * The compression format as well as the kinds of data to compress can be
44
- * configured using the `format` and `constraints` options.
45
- *
46
- * ```diff
47
- * +import { AutoCompress } from '@ember-data-mirror/request-utils/handlers';
48
- * import Fetch from '@ember-data-mirror/request/fetch';
49
- * import RequestManager from '@ember-data-mirror/request';
50
- * import Store from '@ember-data-mirror/store';
51
- *
52
- * class AppStore extends Store {
53
- * requestManager = new RequestManager()
54
- * .use([
55
- * + new AutoCompress(),
56
- * Fetch
57
- * ]);
58
- * }
59
- * ```
60
- *
61
- * @class AutoCompress
62
- * @extends Handler
63
- * @public
64
- * @since 5.5.0
65
- */
66
- class AutoCompress {
67
- constructor(options = {}) {
68
- const opts = {
69
- format: options.format ?? 'gzip',
70
- constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),
71
- allowStreaming: options.allowStreaming ?? false,
72
- forceStreaming: options.forceStreaming ?? false
73
- };
74
- this.options = opts;
75
- }
76
- request({
77
- request
78
- }, next) {
79
- const {
80
- constraints
81
- } = this.options;
82
- const {
83
- body
84
- } = request;
85
- const shouldCompress = isCompressibleMethod(request.method) && request.options?.compress !== false && (
86
- // prettier-ignore
87
- request.options?.compress ? true : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length) : body instanceof Blob ? canCompress('Blob', constraints, body.size) : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength) : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength) : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength) : false);
88
- if (!shouldCompress) return next(request);
89
-
90
- // A convenient way to convert all of the supported body types to a readable
91
- // stream is to use a `Response` object body
92
- const response = new Response(request.body);
93
- const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));
94
- const headers = new Headers(request.headers);
95
- headers.set('Content-Encoding', encodingForFormat(this.options.format));
96
-
97
- //
98
- // For browsers that support it, `fetch` can receive a `ReadableStream` as
99
- // the body, so all we need to do is to create a new `ReadableStream` and
100
- // compress it on the fly
101
- //
102
- const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;
103
- const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;
104
- if (forceStreaming || SupportsRequestStreams && allowStreaming) {
105
- const req = Object.assign({}, request, {
106
- body: stream
107
- });
108
- if (SupportsRequestStreams) {
109
- // @ts-expect-error untyped
110
- req.duplex = 'half';
111
- }
112
- return next(req);
113
-
114
- //
115
- // For non-chromium browsers, we have to "pull" the stream to get the final
116
- // bytes and supply the final byte array as the new request body.
117
- //
118
- } else {
119
- // we need to pull the stream to get the final bytes
120
- const resp = new Response(stream);
121
- return resp.blob().then(blob => {
122
- const req = Object.assign({}, request, {
123
- body: blob,
124
- headers
125
- });
126
- return next(req);
127
- });
128
- }
129
- }
130
- }
131
- function canCompress(type, constraints, size) {
132
- // if we have a value of 0, we can compress anything
133
- if (constraints[type] === 0) return true;
134
- if (constraints[type] === -1) return false;
135
- return size >= constraints[type];
136
- }
137
- function encodingForFormat(format) {
138
- switch (format) {
139
- case 'gzip':
140
- case 'deflate':
141
- case 'deflate-raw':
142
- return format;
143
- default:
144
- throw new Error(`Unsupported compression format: ${format}`);
145
- }
146
- }
147
- export { AutoCompress, SupportsRequestStreams };
1
+ export * from '@warp-drive-mirror/utilities/handlers';
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.js","sources":["../src/-private/handlers/auto-compress.ts"],"sourcesContent":["/**\n * @module @ember-data-mirror/request-utils/handlers\n */\nimport type { Future, Handler, NextFn, RequestContext } from '@ember-data-mirror/request';\nimport type { HTTPMethod } from '@warp-drive-mirror/core-types/request';\n\nfunction isCompressibleMethod(method?: HTTPMethod): boolean {\n return method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE';\n}\n\nexport const SupportsRequestStreams = (() => {\n let duplexAccessed = false;\n\n const hasContentType = new Request('', {\n body: new ReadableStream(),\n method: 'POST',\n // @ts-expect-error untyped\n get duplex() {\n duplexAccessed = true;\n return 'half';\n },\n }).headers.has('Content-Type');\n\n return duplexAccessed && !hasContentType;\n})();\n\ninterface Constraints {\n /**\n * The minimum size at which to compress blobs\n *\n * @default 1000\n * @typedoc\n */\n Blob?: number;\n /**\n * The minimum size at which to compress array buffers\n *\n * @default 1000\n * @typedoc\n */\n ArrayBuffer?: number;\n /**\n * The minimum size at which to compress typed arrays\n *\n * @default 1000\n * @typedoc\n */\n TypedArray?: number;\n /**\n * The minimum size at which to compress data views\n *\n * @default 1000\n * @typedoc\n */\n DataView?: number;\n /**\n * The minimum size at which to compress strings\n *\n * @default 1000\n * @typedoc\n */\n String?: number;\n}\n\n/**\n * Options for configuring the AutoCompress handler.\n *\n * @typedoc\n */\ninterface CompressionOptions {\n /**\n * The compression format to use. Must be a valid\n * compression format supported by [CompressionStream](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The default is `gzip`.\n *\n * @typedoc\n */\n format?: CompressionFormat;\n\n /**\n * Some browsers support `ReadableStream` as a request body. This option\n * enables passing the compression stream as the request body instead of\n * the final compressed body when the browser supports doing so.\n *\n * This comes with several caveats:\n *\n * - the request will be put into `duplex: 'half'` mode. This should be\n * transparent to you, but it is worth noting.\n * - the request mode cannot be `no-cors` as requests with a `ReadableStream`\n * have no content length and thus are a new form of request that triggers\n * cors requirements and a preflight request.\n * - http/1.x is not supported.\n *\n * For additional reading about the restrictions of using `ReadableStream`\n * as a request body, see the [Chromium Documentation](https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#restrictions)\n *\n * Streaming can be enabled per-request in browsers which support it by\n * setting `request.options.allowStreaming` to `true`.\n *\n * Streaming can be forced even when the browser does not support it by setting\n * `request.options.forceStreaming` to `true`. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n * @typedoc\n */\n allowStreaming?: boolean;\n\n /**\n * If `true`, the request will be forced into streaming mode even\n * if the browser does not support it. This is useful if later handlers\n * in the chain can handle the request body as a stream.\n *\n * @default false\n * @typedoc\n */\n forceStreaming?: boolean;\n\n /**\n * The constraints for the request body. This is used to determine\n * whether to compress the request body or not.\n *\n * The defaults are:\n *\n * ```ts\n * {\n * Blob: 1000, // blob.size\n * ArrayBuffer: 1000, // buffer.byteLength\n * TypedArray: 1000, // array.byteLength\n * DataView: 1000, // view.byteLength\n * String: 1000, // string.length\n * }\n * ```\n *\n * The following body types are never compressed unless explicitly\n * configured by the request:\n * - `FormData`\n * - `URLSearchParams`\n * - `ReadableStream`\n *\n * A request.options.compress value of `false` will disable\n * compression for a request body of any type. While a value of\n * `true` will enable compression for the request.\n *\n * An undefined value will use the default, a value of `0` will\n * enable compression for all values, and a value of `-1` will\n * disable compression.\n *\n * @typedoc\n */\n constraints?: Constraints;\n}\n\nconst DEFAULT_CONSTRAINTS = {\n Blob: 1000,\n ArrayBuffer: 1000,\n TypedArray: 1000,\n DataView: 1000,\n String: 1000,\n};\nconst TypedArray = Object.getPrototypeOf(Uint8Array.prototype) as typeof Uint8Array;\n\n/**\n * A request handler that automatically compresses the request body\n * if the request body is a string, array buffer, blob, or form data.\n *\n * This uses the [CompressionStream API](https://developer.mozilla.org/en-US/docs/Web/API/CompressionStream)\n *\n * The compression format as well as the kinds of data to compress can be\n * configured using the `format` and `constraints` options.\n *\n * ```diff\n * +import { AutoCompress } from '@ember-data-mirror/request-utils/handlers';\n * import Fetch from '@ember-data-mirror/request/fetch';\n * import RequestManager from '@ember-data-mirror/request';\n * import Store from '@ember-data-mirror/store';\n *\n * class AppStore extends Store {\n * requestManager = new RequestManager()\n * .use([\n * + new AutoCompress(),\n * Fetch\n * ]);\n * }\n * ```\n *\n * @class AutoCompress\n * @extends Handler\n * @public\n * @since 5.5.0\n */\nexport class AutoCompress implements Handler {\n declare options: Required<CompressionOptions> & { constraints: Required<Constraints> };\n\n constructor(options: CompressionOptions = {}) {\n const opts = {\n format: options.format ?? 'gzip',\n constraints: Object.assign({}, DEFAULT_CONSTRAINTS, options.constraints),\n allowStreaming: options.allowStreaming ?? false,\n forceStreaming: options.forceStreaming ?? false,\n };\n this.options = opts;\n }\n\n request<T>({ request }: RequestContext, next: NextFn<T>): Promise<T> | Future<T> {\n const { constraints } = this.options;\n const { body } = request;\n\n const shouldCompress =\n isCompressibleMethod(request.method) &&\n request.options?.compress !== false &&\n // prettier-ignore\n (request.options?.compress ? true\n : typeof body === 'string' || body instanceof String ? canCompress('String', constraints, body.length)\n : body instanceof Blob ? canCompress('Blob', constraints, body.size)\n : body instanceof ArrayBuffer ? canCompress('ArrayBuffer', constraints, body.byteLength)\n : body instanceof DataView ? canCompress('DataView', constraints, body.byteLength)\n : body instanceof TypedArray ? canCompress('TypedArray', constraints, body.byteLength)\n : false);\n\n if (!shouldCompress) return next(request);\n\n // A convenient way to convert all of the supported body types to a readable\n // stream is to use a `Response` object body\n const response = new Response(request.body);\n const stream = response.body?.pipeThrough(new CompressionStream(this.options.format));\n const headers = new Headers(request.headers);\n headers.set('Content-Encoding', encodingForFormat(this.options.format));\n\n //\n // For browsers that support it, `fetch` can receive a `ReadableStream` as\n // the body, so all we need to do is to create a new `ReadableStream` and\n // compress it on the fly\n //\n const forceStreaming = request.options?.forceStreaming ?? this.options.forceStreaming;\n const allowStreaming = request.options?.allowStreaming ?? this.options.allowStreaming;\n if (forceStreaming || (SupportsRequestStreams && allowStreaming)) {\n const req = Object.assign({}, request, {\n body: stream,\n });\n if (SupportsRequestStreams) {\n // @ts-expect-error untyped\n req.duplex = 'half';\n }\n\n return next(req);\n\n //\n // For non-chromium browsers, we have to \"pull\" the stream to get the final\n // bytes and supply the final byte array as the new request body.\n //\n } else {\n // we need to pull the stream to get the final bytes\n const resp = new Response(stream);\n return resp.blob().then((blob) => {\n const req = Object.assign({}, request, {\n body: blob,\n headers,\n });\n return next(req);\n }) as Promise<T>;\n }\n }\n}\n\nfunction canCompress(type: keyof Constraints, constraints: Required<Constraints>, size: number): boolean {\n // if we have a value of 0, we can compress anything\n if (constraints[type] === 0) return true;\n if (constraints[type] === -1) return false;\n return size >= constraints[type];\n}\n\nfunction encodingForFormat(format: CompressionFormat): string {\n switch (format) {\n case 'gzip':\n case 'deflate':\n case 'deflate-raw':\n return format;\n default:\n throw new Error(`Unsupported compression format: ${format as unknown as string}`);\n }\n}\n"],"names":["isCompressibleMethod","method","SupportsRequestStreams","duplexAccessed","hasContentType","Request","body","ReadableStream","duplex","headers","has","DEFAULT_CONSTRAINTS","Blob","ArrayBuffer","TypedArray","DataView","String","Object","getPrototypeOf","Uint8Array","prototype","AutoCompress","constructor","options","opts","format","constraints","assign","allowStreaming","forceStreaming","request","next","shouldCompress","compress","canCompress","length","size","byteLength","response","Response","stream","pipeThrough","CompressionStream","Headers","set","encodingForFormat","req","resp","blob","then","type","Error"],"mappings":"AAAA;AACA;AACA;;AAIA,SAASA,oBAAoBA,CAACC,MAAmB,EAAW;AAC1D,EAAA,OAAOA,MAAM,KAAK,MAAM,IAAIA,MAAM,KAAK,KAAK,IAAIA,MAAM,KAAK,OAAO,IAAIA,MAAM,KAAK,QAAQ;AAC3F;AAEaC,MAAAA,sBAAsB,GAAG,CAAC,MAAM;EAC3C,IAAIC,cAAc,GAAG,KAAK;AAE1B,EAAA,MAAMC,cAAc,GAAG,IAAIC,OAAO,CAAC,EAAE,EAAE;AACrCC,IAAAA,IAAI,EAAE,IAAIC,cAAc,EAAE;AAC1BN,IAAAA,MAAM,EAAE,MAAM;AACd;IACA,IAAIO,MAAMA,GAAG;AACXL,MAAAA,cAAc,GAAG,IAAI;AACrB,MAAA,OAAO,MAAM;AACf;AACF,GAAC,CAAC,CAACM,OAAO,CAACC,GAAG,CAAC,cAAc,CAAC;EAE9B,OAAOP,cAAc,IAAI,CAACC,cAAc;AAC1C,CAAC;;AAwCD;AACA;AACA;AACA;AACA;;AAsFA,MAAMO,mBAAmB,GAAG;AAC1B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