Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cranq/document-utils

Package Overview
Dependencies
Maintainers
5
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cranq/document-utils - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

2

dist/access/getDocument.d.ts
import { Document } from "../types/Document";
import { DocumentStore } from "../types/DocumentStore";
export declare function getDocument<C extends string, S extends DocumentStore<C, any>, D extends Document>(store: S, collectionId: C, documentId: string | number): D;
export declare function getDocument<C extends string, S extends DocumentStore<C, any>, D extends Document>(store: S, collectionId: C, documentId: string | number): D | undefined;
import { DocumentStore } from "../types/DocumentStore";
import { Field } from "../types/Field";
export declare function getField<C extends string, S extends DocumentStore<C, any>, F extends Field>(store: S, collectionId: C, documentId: string | number, fieldId: string): F;
export declare function getField<C extends string, S extends DocumentStore<C, any>, F extends Field>(store: S, collectionId: C, documentId: string | number, fieldId: string): F | undefined;

@@ -5,2 +5,2 @@ import { Document } from "../types/Document";

import { SchemaStore } from "../types/SchemaStore";
export declare function resolveTrail<C extends string, D extends Document, DS extends DocumentStore<C, any>, SS extends SchemaStore<C>>(store: DS, trail: [C, string, ...Array<string | number>], schema: SS): Document | Field;
export declare function resolveTrail<C extends string, D extends Document, DS extends DocumentStore<C, any>, SS extends SchemaStore<C>>(store: DS, trail: [C, string, ...Array<string | number>], schema: SS): Document | Field | undefined;
import { DeepDocument } from "../types/DeepDocument";
import { DocumentStore } from "../types/DocumentStore";
import { SchemaStore } from "../types/SchemaStore";
export declare function expandReferenceSubgraph<C extends string, DS extends DocumentStore<C, any>, SS extends SchemaStore<C>>(documentStore: DS, collectionId: C, documentId: string, schemaStore: SS): DeepDocument;
export declare function expandReferenceSubgraph<C extends string, DS extends DocumentStore<C, any>, SS extends SchemaStore<C>>(documentStore: DS, collectionId: C, documentId: string, schemaStore: SS): DeepDocument | undefined;

@@ -0,5 +1,5 @@

import { DeepField } from "./DeepField";
import { Field } from "./Field";
import { DeepField } from "./DeepField";
export interface DeepDocument {
[fieldId: string]: Field | DeepField;
}
import { DeepDocument } from "./DeepDocument";
export declare type DeepField = DeepDocument | Array<DeepDocument>;
export declare type DeepField = DeepDocument | undefined | Array<DeepDocument | undefined>;
{
"name": "@cranq/document-utils",
"version": "0.1.0",
"version": "1.0.0",
"description": "Document store manipulation utilities",

@@ -10,3 +10,3 @@ "scripts": {

"author": "Dan Stocker",
"license": "UNLICENSED",
"license": "MIT",
"repository": {

@@ -24,4 +24,4 @@ "type": "git",

"dependencies": {
"@cranq/object-utils": "^0.1.0",
"@cranq/tree-utils": "^0.1.0",
"@cranq/object-utils": "^1.0.0",
"@cranq/tree-utils": "^1.0.1",
"@types/uuid": "^8.0.0",

@@ -28,0 +28,0 @@ "uuid": "^8.3.0"

@@ -19,5 +19,5 @@ import {appendNode} from "@cranq/tree-utils";

): void {
// FIXME: The type cast shouldn't be necessary. Some subtle TS issue is going
// on here.
// FIXME: The type cast shouldn't be necessary.
// Some subtle TS issue is going on here.
appendNode(store, [collectionId, documentId], document as any);
}

@@ -19,5 +19,5 @@ import {appendNodeI} from "@cranq/tree-utils";

): S {
// FIXME: The type cast shouldn't be necessary. Some subtle TS issue is going
// on here.
// FIXME: The type cast shouldn't be necessary.
// Some subtle TS issue is going on here.
return appendNodeI(store, [collectionId, documentId], document as any);
}

@@ -15,4 +15,4 @@ import {getNode} from "@cranq/tree-utils";

documentId: string | number
): D {
return getNode(store, [collectionId, documentId]) as D;
): D | undefined {
return getNode(store, [collectionId, documentId]);
}

@@ -17,5 +17,5 @@ import {getNode} from "@cranq/tree-utils";

fieldId: string
): F {
): F | undefined {
const path = [collectionId, documentId, fieldId];
return getNode(store, path) as F;
return getNode(store, path);
}

@@ -8,2 +8,9 @@ import {getNode} from "@cranq/tree-utils";

/**
* @deprecated Use a series of getDocument() calls instead for type safety.
* @param store Document store container
* @param trail Identifies entry document, then trail of reference fields.
* @param schema Schema store that describes reference fields for the
* specified document store
*/
export function resolveTrail<C extends string, D extends Document, DS extends DocumentStore<C, any>, SS extends SchemaStore<C>>(

@@ -13,3 +20,3 @@ store: DS,

schema: SS
): Document | Field {
): Document | Field | undefined {
let collectionId = trail[0];

@@ -16,0 +23,0 @@ let document = getDocument(store, collectionId, trail[1]);

import {getDocument} from "../access/getDocument";
import {Documentify} from "../types/Documentify";
import {DocumentStore} from "../types/DocumentStore";

@@ -45,3 +46,5 @@ import {SchemaStore} from "../types/SchemaStore";

const result = expandDocumentSubgraph(
getDocument(documentStore, "dogs", "lassie"),
getDocument(
documentStore, "dogs", "lassie"
) as Documentify<any>,
"dogs",

@@ -61,3 +64,5 @@ documentStore,

const result = expandDocumentSubgraph(
getDocument(documentStore, "dogs", "benji"),
getDocument(
documentStore, "dogs", "benji"
) as Documentify<any>,
"dogs",

@@ -75,3 +80,5 @@ documentStore,

it("should return input document", () => {
const document = getDocument(documentStore, "breeds", "jack-russel");
const document = getDocument(
documentStore, "breeds", "jack-russel"
) as Documentify<any>;
const result = expandDocumentSubgraph(

@@ -78,0 +85,0 @@ document,

@@ -33,8 +33,7 @@ import {map} from "@cranq/object-utils";

return value.map(
(item) =>
expandReferenceSubgraph(
documentStore,
referredCollectionId,
item as string,
schemaStore));
(item) => expandReferenceSubgraph(
documentStore,
referredCollectionId,
item as string,
schemaStore));
} else {

@@ -41,0 +40,0 @@ // Single reference

@@ -20,3 +20,3 @@ import {getDocument} from "../access/getDocument";

schemaStore: SS
): DeepDocument {
): DeepDocument | undefined {
const document = getDocument(documentStore, collectionId, documentId);

@@ -23,0 +23,0 @@ return document && expandDocumentSubgraph(

@@ -1,2 +0,2 @@

import {DocumentStore, getDocument, SchemaStore} from "..";
import {Documentify, DocumentStore, getDocument, SchemaStore} from "..";
import {extractDocumentSubgraph} from "./extractDocumentSubgraph";

@@ -43,3 +43,5 @@

const result = extractDocumentSubgraph(
getDocument(documentStore, "dogs", "lassie"),
getDocument(
documentStore, "dogs", "lassie"
) as Documentify<any>,
"dogs",

@@ -55,2 +57,2 @@ documentStore,

});
});
});

@@ -23,4 +23,22 @@ import {getDocument} from "..";

for (const item of value) {
const referredDocument = getDocument(documentStore, referredCollectionId, item as string);
setDocument(result, referredCollectionId, item as string, referredDocument);
const referredDocument =
getDocument(documentStore, referredCollectionId, item as string);
setDocument(
result, referredCollectionId, item as string, referredDocument);
if (referredDocument) {
extractDocumentSubgraph(
referredDocument,
referredCollectionId,
documentStore,
schemaStore,
result);
}
}
} else if (typeof value === "string") {
// Single reference
const referredDocument =
getDocument(documentStore, referredCollectionId, value as string);
setDocument(
result, referredCollectionId, value, referredDocument);
if (referredDocument) {
extractDocumentSubgraph(

@@ -31,16 +49,4 @@ referredDocument,

schemaStore,
result
);
result);
}
} else if (typeof value === "string") {
// Single reference
const referredDocument = getDocument(documentStore, referredCollectionId, value as string);
setDocument(result, referredCollectionId, value, referredDocument);
extractDocumentSubgraph(
referredDocument,
referredCollectionId,
documentStore,
schemaStore,
result
);
}

@@ -47,0 +53,0 @@ }

@@ -24,4 +24,4 @@ import {getDocument} from "../access/getDocument";

const document = getDocument(documentStore, collectionId, documentId);
return document ?
extractDocumentSubgraph(
return document
? extractDocumentSubgraph(
document,

@@ -31,4 +31,4 @@ collectionId,

schemaStore,
result) :
result;
result)
: result;
}

@@ -31,24 +31,34 @@ import {map} from "@cranq/object-utils";

if (schema) {
const document = map(deepDocument, (value, field) => {
const referredCollectionId = schema[field];
if (referredCollectionId !== undefined) {
// Field is reference
if (value instanceof Array) {
// List of references
return (value as Array<Reference>).map(
(item) => createDocument(
item, referredCollectionId, schemaStore, documentStore));
} else if (value !== undefined) {
// Single reference
return createDocument(
value as Reference, referredCollectionId, schemaStore, documentStore);
const document = map(
deepDocument,
(value, field) => {
const referredCollectionId = schema[field];
if (referredCollectionId !== undefined) {
// Field is reference
if (value instanceof Array) {
// List of references
return (value as Array<Reference>).map(
(item) => createDocument(
item,
referredCollectionId,
schemaStore,
documentStore));
} else if (value !== undefined) {
// Single reference
return createDocument(
value as Reference,
referredCollectionId,
schemaStore,
documentStore);
}
} else {
// Field is primitive
return value as Field;
}
} else {
// Field is primitive
return value as Field;
}
});
setDocument(documentStore, collectionId, documentId, document);
});
setDocument(
documentStore, collectionId, documentId, document);
} else {
setDocument(documentStore, collectionId, documentId, deepDocument as Document);
setDocument(
documentStore, collectionId, documentId, deepDocument as Document);
}

@@ -55,0 +65,0 @@ return documentStore;

@@ -0,3 +1,3 @@

import {DeepField} from "./DeepField";
import {Field} from "./Field";
import {DeepField} from "./DeepField";

@@ -4,0 +4,0 @@ /**

@@ -6,2 +6,5 @@ import {DeepDocument} from "./DeepDocument";

*/
export type DeepField = DeepDocument | Array<DeepDocument>;
export type DeepField =
DeepDocument
| undefined
| Array<DeepDocument | undefined>;

@@ -12,3 +12,3 @@ {

"strict": true,
"target": "es5"
"target": "es6"
},

@@ -15,0 +15,0 @@ "exclude": [

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc