@arrirpc/schema 0.63.0 → 0.63.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const jtdUtils = require('jtd-utils');
4
4
  const scule = require('scule');
5
- const timestamp = require('./shared/schema.78a649a7.cjs');
5
+ const timestamp = require('./shared/schema.4e2863ed.cjs');
6
6
 
7
7
  function createParsingTemplate(input, schema) {
8
8
  const fallbackTemplate = `
@@ -983,10 +983,39 @@ function recordTemplate$1(input) {
983
983
  const key = ${keysVarName}[i];
984
984
  const innerVal = ${input.val}[key];
985
985
  if(i !== 0) {
986
- ${input.targetVal} += \`,"\${key}":\`;
986
+ ${input.targetVal} += ",";
987
+ }
988
+ if (key.length < 42) {
989
+ let __result__ = "";
990
+ let __last__ = -1;
991
+ let __point__ = 255;
992
+ let __finished__ = false;
993
+ for (let i = 0; i < key.length; i++) {
994
+ __point__ = key.charCodeAt(i);
995
+ if (__point__ < 32 || (__point__ >= 0xd800 && __point__ <= 0xdfff)) {
996
+ ${input.targetVal} += JSON.stringify(key);
997
+ __finished__ = true;
998
+ break;
999
+ }
1000
+ if (__point__ === 0x22 || __point__ === 0x5c) {
1001
+ __last__ === -1 && (__last__ = 0);
1002
+ __result__ += key.slice(__last__, i) + '\\\\';
1003
+ __last__ = i;
1004
+ }
1005
+ }
1006
+ if(!__finished__) {
1007
+ if (__last__ === -1) {
1008
+ ${input.targetVal} += \`"\${key}"\`;
1009
+ } else {
1010
+ ${input.targetVal} += \`"\${__result__}\${key.slice(__last__)}"\`;
1011
+ }
1012
+ }
1013
+ } else if (key.length < 5000 && !STR_ESCAPE.test(key)) {
1014
+ ${input.targetVal} += \`"\${key}"\`;
987
1015
  } else {
988
- ${input.targetVal} += \`"\${key}":\`;
1016
+ ${input.targetVal} += JSON.stringify(key);
989
1017
  }
1018
+ ${input.targetVal} += ":";
990
1019
  ${innerTemplate}
991
1020
  }`);
992
1021
  templateParts.push(`${input.targetVal} += '}';`);
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { isSchemaFormProperties, isSchemaFormValues, isSchemaFormElements, isSchemaFormDiscriminator, isSchemaFormEmpty, isSchemaFormType, isSchemaFormEnum, isSchemaFormRef } from 'jtd-utils';
2
2
  import { camelCase } from 'scule';
3
- import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as any, v as array, w as boolean, x as clone, y as coerce, z as discriminator, A as enumerator, B as extend, C as float32, D as float64, E as int16, F as int32, G as int64, H as int8, I as nullable, J as number, K as object, L as omit, M as optional, N as parse, O as partial, P as pick, Q as record, R as recursive, S as safeCoerce, T as safeParse, U as serialize, W as string, X as stringEnum, Y as timestamp, Z as uint16, _ as uint32, $ as uint64, a0 as uint8, a1 as validate, a2 as SCHEMA_METADATA } from './shared/schema.31273dd5.mjs';
4
- export { ae as NumberTypeValues, a4 as int64Max, a3 as int64Min, ad as isASchema, af as isObject, ac as isValidationError, a7 as parseObjectSchema, ab as sanitizeJson, a9 as serializeObject, aa as serializeSmallString, a6 as uint64Max, a5 as uint64Min, a8 as validateObjectSchema } from './shared/schema.31273dd5.mjs';
3
+ import { u as uint8Max, a as uint8Min, b as uint16Max, c as uint16Min, d as uint32Max, e as uint32Min, i as int8Max, f as int8Min, g as int16Max, h as int16Min, j as int32Max, k as int32Min, l as isAScalarSchema, m as isAObjectSchema, n as isAStringEnumSchema, o as isAAraySchema, p as isARecordSchema, q as isADiscriminatorSchema, r as isARefSchema, s as errors, V as ValidationError, t as any, v as array, w as boolean, x as clone, y as coerce, z as discriminator, A as enumerator, B as extend, C as float32, D as float64, E as int16, F as int32, G as int64, H as int8, I as nullable, J as number, K as object, L as omit, M as optional, N as parse, O as partial, P as pick, Q as record, R as recursive, S as safeCoerce, T as safeParse, U as serialize, W as string, X as stringEnum, Y as timestamp, Z as uint16, _ as uint32, $ as uint64, a0 as uint8, a1 as validate, a2 as SCHEMA_METADATA } from './shared/schema.25b78dac.mjs';
4
+ export { ae as NumberTypeValues, a4 as int64Max, a3 as int64Min, ad as isASchema, af as isObject, ac as isValidationError, a7 as parseObjectSchema, ab as sanitizeJson, a9 as serializeObject, aa as serializeSmallString, a6 as uint64Max, a5 as uint64Min, a8 as validateObjectSchema } from './shared/schema.25b78dac.mjs';
5
5
 
6
6
  function createParsingTemplate(input, schema) {
7
7
  const fallbackTemplate = `
@@ -982,10 +982,39 @@ function recordTemplate$1(input) {
982
982
  const key = ${keysVarName}[i];
983
983
  const innerVal = ${input.val}[key];
984
984
  if(i !== 0) {
985
- ${input.targetVal} += \`,"\${key}":\`;
985
+ ${input.targetVal} += ",";
986
+ }
987
+ if (key.length < 42) {
988
+ let __result__ = "";
989
+ let __last__ = -1;
990
+ let __point__ = 255;
991
+ let __finished__ = false;
992
+ for (let i = 0; i < key.length; i++) {
993
+ __point__ = key.charCodeAt(i);
994
+ if (__point__ < 32 || (__point__ >= 0xd800 && __point__ <= 0xdfff)) {
995
+ ${input.targetVal} += JSON.stringify(key);
996
+ __finished__ = true;
997
+ break;
998
+ }
999
+ if (__point__ === 0x22 || __point__ === 0x5c) {
1000
+ __last__ === -1 && (__last__ = 0);
1001
+ __result__ += key.slice(__last__, i) + '\\\\';
1002
+ __last__ = i;
1003
+ }
1004
+ }
1005
+ if(!__finished__) {
1006
+ if (__last__ === -1) {
1007
+ ${input.targetVal} += \`"\${key}"\`;
1008
+ } else {
1009
+ ${input.targetVal} += \`"\${__result__}\${key.slice(__last__)}"\`;
1010
+ }
1011
+ }
1012
+ } else if (key.length < 5000 && !STR_ESCAPE.test(key)) {
1013
+ ${input.targetVal} += \`"\${key}"\`;
986
1014
  } else {
987
- ${input.targetVal} += \`"\${key}":\`;
1015
+ ${input.targetVal} += JSON.stringify(key);
988
1016
  }
1017
+ ${input.targetVal} += ":";
989
1018
  ${innerTemplate}
990
1019
  }`);
991
1020
  templateParts.push(`${input.targetVal} += '}';`);
@@ -1484,7 +1484,7 @@ function record(schema, opts = {}) {
1484
1484
  for (const key of Object.keys(input)) {
1485
1485
  const val = input[key];
1486
1486
  strParts.push(
1487
- `"${key}":${schema.metadata[SCHEMA_METADATA].serialize(val, {
1487
+ `${JSON.stringify(key)}:${schema.metadata[SCHEMA_METADATA].serialize(val, {
1488
1488
  instancePath: `${context.instancePath}/${key}`,
1489
1489
  schemaPath: `${context.schemaPath}/values`,
1490
1490
  errors: context.errors
@@ -1486,7 +1486,7 @@ function record(schema, opts = {}) {
1486
1486
  for (const key of Object.keys(input)) {
1487
1487
  const val = input[key];
1488
1488
  strParts.push(
1489
- `"${key}":${schema.metadata[SCHEMA_METADATA].serialize(val, {
1489
+ `${JSON.stringify(key)}:${schema.metadata[SCHEMA_METADATA].serialize(val, {
1490
1490
  instancePath: `${context.instancePath}/${key}`,
1491
1491
  schemaPath: `${context.schemaPath}/values`,
1492
1492
  errors: context.errors
@@ -2,7 +2,7 @@
2
2
 
3
3
  require('jtd-utils');
4
4
  require('scule');
5
- const timestamp = require('./shared/schema.78a649a7.cjs');
5
+ const timestamp = require('./shared/schema.4e2863ed.cjs');
6
6
 
7
7
  const User = timestamp.object({
8
8
  id: timestamp.string(),
@@ -522,7 +522,7 @@ world`,
522
522
  },
523
523
  "record with boolean values": {
524
524
  schema: timestamp.record(timestamp.boolean()),
525
- goodInputs: [{ a: true, b: false }, {}],
525
+ goodInputs: [{ a: true, b: false, [`"C"`]: true }, {}],
526
526
  badInputs: [{ a: true, b: true, c: "true" }, { a: "null" }, null]
527
527
  },
528
528
  "record with objects": {
@@ -1291,6 +1291,16 @@ Sed in commodo libero. Vestibulum sit amet convallis libero. Aenean tincidunt so
1291
1291
  description: "hello \xFF"
1292
1292
  }
1293
1293
  ]
1294
+ },
1295
+ "record with quoted keys": {
1296
+ schema: timestamp.record(timestamp.boolean()),
1297
+ inputs: [
1298
+ {
1299
+ A: true,
1300
+ '"B"': false,
1301
+ " C": true
1302
+ }
1303
+ ]
1294
1304
  }
1295
1305
  };
1296
1306
 
@@ -1,6 +1,6 @@
1
1
  import 'jtd-utils';
2
2
  import 'scule';
3
- import { K as object, W as string, M as optional, I as nullable, F as int32, z as discriminator, w as boolean, X as stringEnum, v as array, Y as timestamp, _ as uint32, t as any, J as number, Q as record, R as recursive, D as float64, C as float32, G as int64, E as int16, Z as uint16, H as int8, a0 as uint8, O as partial, $ as uint64, P as pick, A as enumerator } from './shared/schema.31273dd5.mjs';
3
+ import { K as object, W as string, M as optional, I as nullable, F as int32, z as discriminator, w as boolean, X as stringEnum, v as array, Y as timestamp, _ as uint32, t as any, J as number, Q as record, R as recursive, D as float64, C as float32, G as int64, E as int16, Z as uint16, H as int8, a0 as uint8, O as partial, $ as uint64, P as pick, A as enumerator } from './shared/schema.25b78dac.mjs';
4
4
 
5
5
  const User = object({
6
6
  id: string(),
@@ -520,7 +520,7 @@ world`,
520
520
  },
521
521
  "record with boolean values": {
522
522
  schema: record(boolean()),
523
- goodInputs: [{ a: true, b: false }, {}],
523
+ goodInputs: [{ a: true, b: false, [`"C"`]: true }, {}],
524
524
  badInputs: [{ a: true, b: true, c: "true" }, { a: "null" }, null]
525
525
  },
526
526
  "record with objects": {
@@ -1289,6 +1289,16 @@ Sed in commodo libero. Vestibulum sit amet convallis libero. Aenean tincidunt so
1289
1289
  description: "hello \xFF"
1290
1290
  }
1291
1291
  ]
1292
+ },
1293
+ "record with quoted keys": {
1294
+ schema: record(boolean()),
1295
+ inputs: [
1296
+ {
1297
+ A: true,
1298
+ '"B"': false,
1299
+ " C": true
1300
+ }
1301
+ ]
1292
1302
  }
1293
1303
  };
1294
1304
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/schema",
3
- "version": "0.63.0",
3
+ "version": "0.63.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "scule": "^1.3.0",
26
26
  "uncrypto": "^0.1.3",
27
- "jtd-utils": "0.63.0"
27
+ "jtd-utils": "0.63.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "ajv": "^8.17.1",