@oada/client
Advanced tools
Comparing version 4.5.0 to 4.5.2
@@ -40,1 +40,2 @@ /** | ||
export declare type Change = ChangeArray[0]; | ||
export { JobsRequest, JobEventType, doJob } from './jobs.js'; |
@@ -46,2 +46,3 @@ /** | ||
export { OADAClient } from './client.js'; | ||
export { JobsRequest, doJob } from './jobs.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -17,6 +17,2 @@ /** | ||
*/ | ||
/** | ||
* @packageDocumentation | ||
* Some useful functions | ||
*/ | ||
import type { Tree } from '@oada/types/oada/tree/v1.js'; | ||
@@ -46,1 +42,2 @@ export declare function toArray<E extends unknown[] | readonly unknown[]>(itemOrArray: E | E[0]): E; | ||
}>(error: E): Promise<E & Error>; | ||
export declare const changeSym: unique symbol; |
@@ -17,2 +17,4 @@ /** | ||
*/ | ||
import { JsonPointer } from 'json-ptr'; | ||
import objectAssignDeep from 'object-assign-deep'; | ||
// Typescript sucks at figuring out Array.isArray on its own | ||
@@ -121,2 +123,55 @@ function isArray(value) { | ||
} | ||
export const changeSym = Symbol('change'); | ||
/** | ||
* Tell TS we should never reach here (i.e., this should never be called) | ||
* @internal | ||
*/ | ||
export function assertNever(value, message) { | ||
throw new Error(message ?? `Bad value: ${value}`); | ||
} | ||
/** | ||
* Replace `null` values in delete changes with `undefined` | ||
* @internal | ||
*/ | ||
export function translateDelete(body) { | ||
if (body === null) { | ||
return undefined; | ||
} | ||
if (typeof body !== 'object') { | ||
return body; | ||
} | ||
if (Array.isArray(body)) { | ||
return body.map((item) => translateDelete(item)); | ||
} | ||
return Object.fromEntries(Object.entries(body).map(([key, value]) => [ | ||
key, | ||
translateDelete(value), | ||
])); | ||
} | ||
/** | ||
* Construct object representing the change tree | ||
* @internal | ||
*/ | ||
export function buildChangeObject(rootChange, ...children) { | ||
const changeBody = { | ||
[changeSym]: [rootChange], | ||
...(rootChange.type === 'delete' | ||
? translateDelete(rootChange.body) | ||
: rootChange.body), | ||
}; | ||
for (const change of children) { | ||
const ptr = JsonPointer.create(change.path); | ||
const old = ptr.get(changeBody); | ||
// eslint-disable-next-line security/detect-object-injection | ||
const changes = old?.[changeSym] ?? []; | ||
const body = change.type === 'delete' | ||
? translateDelete(change.body) | ||
: change.body; | ||
const merged = objectAssignDeep(old ?? {}, body); | ||
// eslint-disable-next-line security/detect-object-injection | ||
merged[changeSym] = [...changes, change]; | ||
ptr.set(changeBody, merged, true); | ||
} | ||
return changeBody; | ||
} | ||
//# sourceMappingURL=utils.js.map |
@@ -91,1 +91,3 @@ /** | ||
export type Change = ChangeArray[0]; | ||
export { JobsRequest, JobEventType, doJob } from './jobs.js'; |
@@ -22,4 +22,6 @@ /** | ||
*/ | ||
import type { Change, Json, JsonObject } from './index.js'; | ||
import type { Tree, TreeKey } from '@oada/types/oada/tree/v1.js'; | ||
import { JsonPointer } from 'json-ptr'; | ||
import objectAssignDeep from 'object-assign-deep'; | ||
@@ -163,1 +165,82 @@ // Typescript sucks at figuring out Array.isArray on its own | ||
} | ||
export const changeSym = Symbol('change'); | ||
/** | ||
* @internal | ||
*/ | ||
export type ChangeBody<T> = T & { | ||
[changeSym]?: Array<Readonly<Change>>; | ||
}; | ||
/** | ||
* Tell TS we should never reach here (i.e., this should never be called) | ||
* @internal | ||
*/ | ||
export function assertNever(value: never, message?: string): never { | ||
throw new Error(message ?? `Bad value: ${value}`); | ||
} | ||
/** | ||
* Replace `null` values in delete changes with `undefined` | ||
* @internal | ||
*/ | ||
export function translateDelete(body: Json): Json | undefined { | ||
if (body === null) { | ||
return undefined; | ||
} | ||
if (typeof body !== 'object') { | ||
return body; | ||
} | ||
if (Array.isArray(body)) { | ||
return body.map((item) => translateDelete(item) as Json); | ||
} | ||
return Object.fromEntries( | ||
Object.entries(body).map(([key, value]) => [ | ||
key, | ||
translateDelete(value!) as Json, | ||
]) | ||
); | ||
} | ||
/** | ||
* Construct object representing the change tree | ||
* @internal | ||
*/ | ||
export function buildChangeObject(rootChange: Change, ...children: Change[]) { | ||
const changeBody: ChangeBody<unknown> = { | ||
[changeSym]: [rootChange], | ||
...(rootChange.type === 'delete' | ||
? (translateDelete(rootChange.body as Json) as JsonObject) | ||
: rootChange.body), | ||
}; | ||
for (const change of children) { | ||
const ptr = JsonPointer.create(change.path); | ||
const old = ptr.get(changeBody) as ChangeBody<unknown>; | ||
// eslint-disable-next-line security/detect-object-injection | ||
const changes = old?.[changeSym] ?? []; | ||
const body = | ||
change.type === 'delete' | ||
? translateDelete(change.body as Json) | ||
: change.body; | ||
const merged = objectAssignDeep(old ?? {}, body); | ||
// eslint-disable-next-line security/detect-object-injection | ||
merged[changeSym] = [...changes, change]; | ||
ptr.set(changeBody, merged, true); | ||
} | ||
return changeBody; | ||
} | ||
/** | ||
* @internal | ||
*/ | ||
export interface Result<T, P = unknown> { | ||
value: T; | ||
path: string; | ||
pointer: string; | ||
parent: P; | ||
parentProperty: string; | ||
} |
{ | ||
"name": "@oada/client", | ||
"version": "4.5.0", | ||
"version": "4.5.2", | ||
"description": "A lightweight client tool to interact with an OADA-compliant server", | ||
@@ -86,3 +86,4 @@ "repository": "https://github.com/OADA/client", | ||
"dependencies": { | ||
"@oada/types": "^3.3.0", | ||
"@oada/jobs": "^4.2.5", | ||
"@oada/types": "^3.4.6", | ||
"abort-controller": "^3.0.0", | ||
@@ -101,8 +102,12 @@ "buffer": "^6.0.3", | ||
"isomorphic-ws": "^5.0.0", | ||
"json-ptr": "^3.1.1", | ||
"jsonpath-plus": "^7.2.0", | ||
"media-type": "^0.3.1", | ||
"object-assign-deep": "^0.4.0", | ||
"p-queue": "^7.3.0", | ||
"reconnecting-websocket": "^4.4.0", | ||
"resolve-alpn": "^1.2.1", | ||
"serialize-error": "^11.0.0", | ||
"supports-color": "^9.2.3", | ||
"tslib": "^2.4.0", | ||
"tslib": "^2.5.0", | ||
"utf-8-validate": "^5.0.9", | ||
@@ -117,2 +122,3 @@ "ws": "^8.9.0", | ||
"@types/node": "^16.11.65", | ||
"@types/object-assign-deep": "^0", | ||
"@types/ws": "^8.5.3", | ||
@@ -119,0 +125,0 @@ "@typescript-eslint/eslint-plugin": "^5.40.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1738301
65
27428
6
28
41
+ Added@oada/jobs@^4.2.5
+ Addedjson-ptr@^3.1.1
+ Addedjsonpath-plus@^7.2.0
+ Addedobject-assign-deep@^0.4.0
+ Addedserialize-error@^11.0.0
+ Added@ava/typescript@4.1.0(transitive)
+ Added@bcoe/v8-coverage@0.2.3(transitive)
+ Added@istanbuljs/schema@0.1.3(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Added@oada/jobs@4.5.2(transitive)
+ Added@oada/list-lib@4.3.0(transitive)
+ Added@oada/oadaify@2.1.0(transitive)
+ Added@rollup/pluginutils@4.2.1(transitive)
+ Added@sindresorhus/is@6.3.1(transitive)
+ Added@sindresorhus/merge-streams@2.3.0(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/luxon@3.4.2(transitive)
+ Added@vercel/nft@0.26.5(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedacorn@8.12.1(transitive)
+ Addedacorn-import-attributes@1.9.5(transitive)
+ Addedacorn-walk@8.3.4(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedarray-find-index@1.0.2(transitive)
+ Addedarrgv@1.0.2(transitive)
+ Addedarrify@3.0.0(transitive)
+ Addedasync-sema@3.1.1(transitive)
+ Addedava@6.1.3(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase-convert-int-array@1.0.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedblueimp-md5@2.19.0(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addedc8@9.1.0(transitive)
+ Addedcallsites@4.2.0(transitive)
+ Addedcbor@9.0.2(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedchunkd@2.0.1(transitive)
+ Addedci-info@4.0.0(transitive)
+ Addedci-parallel-vars@1.0.1(transitive)
+ Addedcli-truncate@4.0.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedclone-deep@4.0.1(transitive)
+ Addedcode-excerpt@4.0.0(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedcommon-path-prefix@3.0.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconcordance@5.0.4(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addedconvert-source-map@2.0.0(transitive)
+ Addedconvert-to-spaces@2.0.1(transitive)
+ Addedcron@3.1.7(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedcsvjson@5.1.0(transitive)
+ Addedcurrently-unhandled@0.4.1(transitive)
+ Addeddate-time@3.1.0(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedemittery@1.0.3(transitive)
+ Addedemoji-regex@10.4.08.0.0(transitive)
+ Addedescalade@3.2.0(transitive)
+ Addedescape-string-regexp@2.0.05.0.0(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestree-walker@2.0.2(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedexeca@7.2.0(transitive)
+ Addedfast-diff@1.3.0(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfigures@6.1.0(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedfind-up-simple@1.0.0(transitive)
+ Addedforeach@2.0.6(transitive)
+ Addedforeground-child@3.3.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedget-caller-file@2.0.5(transitive)
+ Addedget-east-asian-width@1.2.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@14.0.2(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhtml-escaper@2.0.2(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedhuman-signals@4.3.1(transitive)
+ Addedignore@5.3.2(transitive)
+ Addedignore-by-default@2.1.0(transitive)
+ Addedimurmurhash@0.1.4(transitive)
+ Addedindent-string@5.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedirregular-plurals@3.5.0(transitive)
+ Addedis-extglob@2.1.1(transitive)
+ Addedis-fullwidth-code-point@3.0.04.0.0(transitive)
+ Addedis-glob@4.0.3(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedis-plain-object@2.0.45.0.0(transitive)
+ Addedis-promise@4.0.0(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedis-unicode-supported@2.1.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedistanbul-lib-coverage@3.2.2(transitive)
+ Addedistanbul-lib-report@3.0.1(transitive)
+ Addedistanbul-reports@3.1.7(transitive)
+ Addedjs-string-escape@1.0.1(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedjson-pointer@0.6.2(transitive)
+ Addedjson-ptr@3.1.1(transitive)
+ Addedjsonpath-plus@7.2.08.1.0(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedksuid@3.0.0(transitive)
+ Addedload-json-file@7.0.1(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedluxon@3.4.4(transitive)
+ Addedmake-dir@3.1.04.0.0(transitive)
+ Addedmatcher@5.0.0(transitive)
+ Addedmd5-hex@3.0.1(transitive)
+ Addedmemoize@10.0.0(transitive)
+ Addedmerge-stream@2.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addedmimic-function@5.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addednofilter@3.1.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedobject-assign-deep@0.4.0(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedp-map@7.0.2(transitive)
+ Addedp-queue@8.0.1(transitive)
+ Addedp-timeout@6.1.2(transitive)
+ Addedpackage-config@5.0.0(transitive)
+ Addedparse-ms@4.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-key@3.1.14.0.0(transitive)
+ Addedpath-type@5.0.0(transitive)
+ Addedpicomatch@2.3.13.0.1(transitive)
+ Addedplur@5.1.0(transitive)
+ Addedpretty-ms@9.1.0(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedrequire-directory@2.1.1(transitive)
+ Addedresolve-cwd@3.0.0(transitive)
+ Addedresolve-from@5.0.0(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedserialize-error@11.0.37.0.1(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedshallow-clone@3.0.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@3.0.74.1.0(transitive)
+ Addedslash@5.1.0(transitive)
+ Addedslice-ansi@5.0.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedstack-utils@2.0.6(transitive)
+ Addedstring-width@4.2.37.2.0(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
+ Addedsupertap@3.0.1(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtemp-dir@3.0.0(transitive)
+ Addedtest-exclude@6.0.0(transitive)
+ Addedtime-zone@1.0.0(transitive)
+ Addedtiny-json-http@7.5.1(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedtype-fest@0.13.12.19.0(transitive)
+ Addedunicorn-magic@0.1.0(transitive)
+ Addedv8-to-istanbul@9.3.0(transitive)
+ Addedwell-known-symbols@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrap-ansi@7.0.0(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedwrite-file-atomic@5.0.1(transitive)
+ Addedy18n@5.0.8(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
+ Addedyocto-queue@0.1.0(transitive)
Updated@oada/types@^3.4.6
Updatedtslib@^2.5.0