@verdant-web/common 1.15.2 → 1.15.3
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/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +6 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/oids.d.ts +4 -0
- package/dist/cjs/oids.js +19 -1
- package/dist/cjs/oids.js.map +1 -1
- package/dist/cjs/oids.test.js +76 -0
- package/dist/cjs/oids.test.js.map +1 -1
- package/dist/cjs/refs.d.ts +2 -0
- package/dist/cjs/refs.js +9 -1
- package/dist/cjs/refs.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/oids.d.ts +4 -0
- package/dist/esm/oids.js +15 -0
- package/dist/esm/oids.js.map +1 -1
- package/dist/esm/oids.test.js +77 -1
- package/dist/esm/oids.test.js.map +1 -1
- package/dist/esm/refs.d.ts +2 -0
- package/dist/esm/refs.js +6 -0
- package/dist/esm/refs.js.map +1 -1
- package/dist/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/oids.test.ts +82 -0
- package/src/oids.ts +17 -0
- package/src/refs.ts +8 -0
package/src/oids.test.ts
CHANGED
|
@@ -19,6 +19,9 @@ import {
|
|
|
19
19
|
ObjectIdentifier,
|
|
20
20
|
removeOidPropertiesFromAllSubObjects,
|
|
21
21
|
getLegacyDotOidSubIdRange,
|
|
22
|
+
replaceLegacyOidsInJsonString,
|
|
23
|
+
MATCH_LEGACY_OID_JSON_STRING,
|
|
24
|
+
replaceLegacyOidsInObject,
|
|
22
25
|
} from './oids.js';
|
|
23
26
|
|
|
24
27
|
describe('normalizing an object', () => {
|
|
@@ -450,4 +453,83 @@ describe('handling legacy OIDs', () => {
|
|
|
450
453
|
),
|
|
451
454
|
).toBe(true);
|
|
452
455
|
});
|
|
456
|
+
it.each([
|
|
457
|
+
['items/clabgyjfh00003968qycsq3ld.inputs.#:baz', true],
|
|
458
|
+
// include more unicode chars
|
|
459
|
+
['items/clabgyjfh00003968qycsq3ld\ufea3.inputs\u39fc.#:baz!!!', true],
|
|
460
|
+
// not matching new oids
|
|
461
|
+
['items/clabgyjfh00003968qycsq3ld', false],
|
|
462
|
+
['items/clabgyjfh00003968qycsq3ld:baz', false],
|
|
463
|
+
['items/clabgyjfh00003968qycsq3ld:baz1111', false],
|
|
464
|
+
])('matches legacy oids', (oid, match) => {
|
|
465
|
+
expect(MATCH_LEGACY_OID_JSON_STRING.test('"' + oid + '"'), oid).toBe(match);
|
|
466
|
+
// regex are stateful 🙄
|
|
467
|
+
MATCH_LEGACY_OID_JSON_STRING.lastIndex = 0;
|
|
468
|
+
});
|
|
469
|
+
it.each([
|
|
470
|
+
[
|
|
471
|
+
{ op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz' },
|
|
472
|
+
{ op: 'delete', oid: 'items/clabgyjfh00003968qycsq3ld:baz' },
|
|
473
|
+
],
|
|
474
|
+
[
|
|
475
|
+
{
|
|
476
|
+
op: 'list-push',
|
|
477
|
+
oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
|
|
478
|
+
value: {
|
|
479
|
+
'@@type': 'ref',
|
|
480
|
+
id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
|
|
481
|
+
},
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
op: 'list-push',
|
|
485
|
+
oid: 'items/clabgyjfh00003968qycsq3ld:baz',
|
|
486
|
+
value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
|
|
487
|
+
},
|
|
488
|
+
],
|
|
489
|
+
[
|
|
490
|
+
{
|
|
491
|
+
op: 'list-remove',
|
|
492
|
+
oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
|
|
493
|
+
value: {
|
|
494
|
+
'@@type': 'ref',
|
|
495
|
+
id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
op: 'list-remove',
|
|
500
|
+
oid: 'items/clabgyjfh00003968qycsq3ld:baz',
|
|
501
|
+
value: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
[
|
|
505
|
+
{
|
|
506
|
+
oid: 'items/clabgyjfh00003968qycsq3ld.inputs.#:baz',
|
|
507
|
+
timestamp: '2021-03-04T21:00:00.000Z',
|
|
508
|
+
snapshot: {
|
|
509
|
+
foo: 1,
|
|
510
|
+
bar: {
|
|
511
|
+
'@@type': 'ref',
|
|
512
|
+
id: 'items/clabgyjfh00003968qycsq3ld.inputs.#:qux',
|
|
513
|
+
},
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
oid: 'items/clabgyjfh00003968qycsq3ld:baz',
|
|
518
|
+
timestamp: '2021-03-04T21:00:00.000Z',
|
|
519
|
+
snapshot: {
|
|
520
|
+
foo: 1,
|
|
521
|
+
bar: { '@@type': 'ref', id: 'items/clabgyjfh00003968qycsq3ld:qux' },
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
],
|
|
525
|
+
[
|
|
526
|
+
{ oid: 'test thing/what if.boo.blah so what:fajsdfj' },
|
|
527
|
+
{ oid: 'test thing/what if:fajsdfj' },
|
|
528
|
+
],
|
|
529
|
+
])(
|
|
530
|
+
'should replace legacy OIDs in a JSON string with new OIDs',
|
|
531
|
+
(from, to) => {
|
|
532
|
+
expect(replaceLegacyOidsInObject(from), JSON.stringify(from)).toEqual(to);
|
|
533
|
+
},
|
|
534
|
+
);
|
|
453
535
|
});
|
package/src/oids.ts
CHANGED
|
@@ -500,3 +500,20 @@ export function isLegacyDotOid(oid: ObjectIdentifier) {
|
|
|
500
500
|
const partBeforeRandomSep = oid.split(RANDOM_SEPARATOR)[0];
|
|
501
501
|
return partBeforeRandomSep.includes('.');
|
|
502
502
|
}
|
|
503
|
+
|
|
504
|
+
export function convertLegacyOid(oid: ObjectIdentifier) {
|
|
505
|
+
const { collection, id, subId } = decomposeOid(oid);
|
|
506
|
+
return createOid(collection, id, subId);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export const MATCH_LEGACY_OID_JSON_STRING = /"[^"]+\/[^"]+?(\.[^"]+)+\:[^"]+"/g;
|
|
510
|
+
export function replaceLegacyOidsInJsonString(string: string) {
|
|
511
|
+
// replace every match of a legacy OID, converting to a new OID
|
|
512
|
+
return string.replaceAll(MATCH_LEGACY_OID_JSON_STRING, (match) => {
|
|
513
|
+
const legacyOid = match.slice(1, match.length - 1);
|
|
514
|
+
return `"${convertLegacyOid(legacyOid)}"`;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
export function replaceLegacyOidsInObject(obj: any) {
|
|
518
|
+
return JSON.parse(replaceLegacyOidsInJsonString(JSON.stringify(obj)));
|
|
519
|
+
}
|
package/src/refs.ts
CHANGED
|
@@ -14,3 +14,11 @@ export function compareRefs(a: any, b: any) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export type Ref = ObjectRef | FileRef;
|
|
17
|
+
|
|
18
|
+
export function makeObjectRef(oid: string): ObjectRef {
|
|
19
|
+
return { '@@type': 'ref', id: oid };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function makeFileRef(oid: string): FileRef {
|
|
23
|
+
return { '@@type': 'file', id: oid };
|
|
24
|
+
}
|