@smithy/core 3.23.10 → 3.23.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.
@@ -218,11 +218,15 @@ const error = (namespace, name, traits, memberNames, memberList, ctor) => Schema
218
218
  ctor: null,
219
219
  });
220
220
 
221
+ const traitsCache = [];
221
222
  function translateTraits(indicator) {
222
223
  if (typeof indicator === "object") {
223
224
  return indicator;
224
225
  }
225
226
  indicator = indicator | 0;
227
+ if (traitsCache[indicator]) {
228
+ return traitsCache[indicator];
229
+ }
226
230
  const traits = {};
227
231
  let i = 0;
228
232
  for (const trait of [
@@ -238,12 +242,15 @@ function translateTraits(indicator) {
238
242
  traits[trait] = 1;
239
243
  }
240
244
  }
241
- return traits;
245
+ return (traitsCache[indicator] = traits);
242
246
  }
243
247
 
244
248
  const anno = {
245
249
  it: Symbol.for("@smithy/nor-struct-it"),
250
+ ns: Symbol.for("@smithy/ns"),
246
251
  };
252
+ const simpleSchemaCacheN = [];
253
+ const simpleSchemaCacheS = {};
247
254
  class NormalizedSchema {
248
255
  ref;
249
256
  memberName;
@@ -308,6 +315,22 @@ class NormalizedSchema {
308
315
  return isPrototype;
309
316
  }
310
317
  static of(ref) {
318
+ const keyAble = typeof ref === "function" || (typeof ref === "object" && ref !== null);
319
+ if (typeof ref === "number") {
320
+ if (simpleSchemaCacheN[ref]) {
321
+ return simpleSchemaCacheN[ref];
322
+ }
323
+ }
324
+ else if (typeof ref === "string") {
325
+ if (simpleSchemaCacheS[ref]) {
326
+ return simpleSchemaCacheS[ref];
327
+ }
328
+ }
329
+ else if (keyAble) {
330
+ if (ref[anno.ns]) {
331
+ return ref[anno.ns];
332
+ }
333
+ }
311
334
  const sc = deref(ref);
312
335
  if (sc instanceof NormalizedSchema) {
313
336
  return sc;
@@ -320,7 +343,17 @@ class NormalizedSchema {
320
343
  }
321
344
  throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
322
345
  }
323
- return new NormalizedSchema(sc);
346
+ const ns = new NormalizedSchema(sc);
347
+ if (keyAble) {
348
+ return (ref[anno.ns] = ns);
349
+ }
350
+ if (typeof sc === "string") {
351
+ return (simpleSchemaCacheS[sc] = ns);
352
+ }
353
+ if (typeof sc === "number") {
354
+ return (simpleSchemaCacheN[sc] = ns);
355
+ }
356
+ return ns;
324
357
  }
325
358
  getSchema() {
326
359
  const sc = this.schema;
@@ -658,5 +691,8 @@ exports.operation = operation;
658
691
  exports.serializerMiddlewareOption = serializerMiddlewareOption;
659
692
  exports.sim = sim;
660
693
  exports.simAdapter = simAdapter;
694
+ exports.simpleSchemaCacheN = simpleSchemaCacheN;
695
+ exports.simpleSchemaCacheS = simpleSchemaCacheS;
661
696
  exports.struct = struct;
697
+ exports.traitsCache = traitsCache;
662
698
  exports.translateTraits = translateTraits;
@@ -2,7 +2,10 @@ import { deref } from "../deref";
2
2
  import { translateTraits } from "./translateTraits";
3
3
  const anno = {
4
4
  it: Symbol.for("@smithy/nor-struct-it"),
5
+ ns: Symbol.for("@smithy/ns"),
5
6
  };
7
+ export const simpleSchemaCacheN = [];
8
+ export const simpleSchemaCacheS = {};
6
9
  export class NormalizedSchema {
7
10
  ref;
8
11
  memberName;
@@ -67,6 +70,22 @@ export class NormalizedSchema {
67
70
  return isPrototype;
68
71
  }
69
72
  static of(ref) {
73
+ const keyAble = typeof ref === "function" || (typeof ref === "object" && ref !== null);
74
+ if (typeof ref === "number") {
75
+ if (simpleSchemaCacheN[ref]) {
76
+ return simpleSchemaCacheN[ref];
77
+ }
78
+ }
79
+ else if (typeof ref === "string") {
80
+ if (simpleSchemaCacheS[ref]) {
81
+ return simpleSchemaCacheS[ref];
82
+ }
83
+ }
84
+ else if (keyAble) {
85
+ if (ref[anno.ns]) {
86
+ return ref[anno.ns];
87
+ }
88
+ }
70
89
  const sc = deref(ref);
71
90
  if (sc instanceof NormalizedSchema) {
72
91
  return sc;
@@ -79,7 +98,17 @@ export class NormalizedSchema {
79
98
  }
80
99
  throw new Error(`@smithy/core/schema - may not init unwrapped member schema=${JSON.stringify(ref, null, 2)}.`);
81
100
  }
82
- return new NormalizedSchema(sc);
101
+ const ns = new NormalizedSchema(sc);
102
+ if (keyAble) {
103
+ return (ref[anno.ns] = ns);
104
+ }
105
+ if (typeof sc === "string") {
106
+ return (simpleSchemaCacheS[sc] = ns);
107
+ }
108
+ if (typeof sc === "number") {
109
+ return (simpleSchemaCacheN[sc] = ns);
110
+ }
111
+ return ns;
83
112
  }
84
113
  getSchema() {
85
114
  const sc = this.schema;
@@ -1,8 +1,12 @@
1
+ export const traitsCache = [];
1
2
  export function translateTraits(indicator) {
2
3
  if (typeof indicator === "object") {
3
4
  return indicator;
4
5
  }
5
6
  indicator = indicator | 0;
7
+ if (traitsCache[indicator]) {
8
+ return traitsCache[indicator];
9
+ }
6
10
  const traits = {};
7
11
  let i = 0;
8
12
  for (const trait of [
@@ -18,5 +22,5 @@ export function translateTraits(indicator) {
18
22
  traits[trait] = 1;
19
23
  }
20
24
  }
21
- return traits;
25
+ return (traitsCache[indicator] = traits);
22
26
  }
@@ -1,4 +1,15 @@
1
1
  import type { $MemberSchema, $Schema, $SchemaRef, NormalizedSchema as INormalizedSchema, SchemaRef, SchemaTraitsObject, StaticSchema } from "@smithy/types";
2
+ /**
3
+ * Cache for numeric schemaRef. Having separate cache objects for number/string improves
4
+ * lookup performance.
5
+ * @internal
6
+ */
7
+ export declare const simpleSchemaCacheN: Array<NormalizedSchema | undefined>;
8
+ /**
9
+ * Cache for string schemaRef.
10
+ * @internal
11
+ */
12
+ export declare const simpleSchemaCacheS: Record<string, NormalizedSchema>;
2
13
  /**
3
14
  * Wraps both class instances, numeric sentinel values, and member schema pairs.
4
15
  * Presents a consistent interface for interacting with polymorphic schema representations.
@@ -1,4 +1,10 @@
1
1
  import type { SchemaTraits, SchemaTraitsObject } from "@smithy/types";
2
+ /**
3
+ * Module-level cache for translateTraits() numeric bitmask inputs.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare const traitsCache: SchemaTraitsObject[];
2
8
  /**
3
9
  * @internal
4
10
  * @param indicator - numeric indicator for preset trait combination.
@@ -1,4 +1,15 @@
1
1
  import { $MemberSchema, $Schema, $SchemaRef, NormalizedSchema as INormalizedSchema, SchemaRef, SchemaTraitsObject, StaticSchema } from "@smithy/types";
2
+ /**
3
+ * Cache for numeric schemaRef. Having separate cache objects for number/string improves
4
+ * lookup performance.
5
+ * @internal
6
+ */
7
+ export declare const simpleSchemaCacheN: Array<NormalizedSchema | undefined>;
8
+ /**
9
+ * Cache for string schemaRef.
10
+ * @internal
11
+ */
12
+ export declare const simpleSchemaCacheS: Record<string, NormalizedSchema>;
2
13
  /**
3
14
  * Wraps both class instances, numeric sentinel values, and member schema pairs.
4
15
  * Presents a consistent interface for interacting with polymorphic schema representations.
@@ -1,4 +1,10 @@
1
1
  import { SchemaTraits, SchemaTraitsObject } from "@smithy/types";
2
+ /**
3
+ * Module-level cache for translateTraits() numeric bitmask inputs.
4
+ *
5
+ * @internal
6
+ */
7
+ export declare const traitsCache: SchemaTraitsObject[];
2
8
  /**
3
9
  * @internal
4
10
  * @param indicator - numeric indicator for preset trait combination.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.23.10",
3
+ "version": "3.23.11",
4
4
  "scripts": {
5
5
  "build": "yarn lint && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
6
6
  "build:cjs": "node ../../scripts/inline core",
@@ -92,7 +92,7 @@
92
92
  "@smithy/util-base64": "^4.3.2",
93
93
  "@smithy/util-body-length-browser": "^4.2.2",
94
94
  "@smithy/util-middleware": "^4.2.12",
95
- "@smithy/util-stream": "^4.5.18",
95
+ "@smithy/util-stream": "^4.5.19",
96
96
  "@smithy/util-utf8": "^4.2.2",
97
97
  "@smithy/uuid": "^1.1.2",
98
98
  "tslib": "^2.6.2"