@org-quicko/silo-client 1.0.0 → 1.0.1
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/README.md +159 -124
- package/dist/collections/collection-handle.d.cts +15 -23
- package/dist/collections/collection-handle.d.ts +15 -23
- package/dist/collections/collections.d.cts +3 -5
- package/dist/collections/collections.d.ts +3 -5
- package/dist/entries/entry-envelope.d.cts +18 -0
- package/dist/entries/entry-envelope.d.ts +18 -0
- package/dist/entries/entry-read-options.d.cts +16 -0
- package/dist/entries/entry-read-options.d.ts +16 -0
- package/dist/entries/entry-reader.d.cts +16 -16
- package/dist/entries/entry-reader.d.ts +16 -16
- package/dist/entries/entry.d.cts +11 -23
- package/dist/entries/entry.d.ts +11 -23
- package/dist/index.cjs +29 -153
- package/dist/index.d.cts +3 -5
- package/dist/index.d.ts +3 -5
- package/dist/index.js +29 -153
- package/dist/search/search-hit.d.cts +5 -5
- package/dist/search/search-hit.d.ts +5 -5
- package/dist/search/search.d.cts +4 -1
- package/dist/search/search.d.ts +4 -1
- package/package.json +58 -58
- package/dist/collections/reserved-field-names.d.cts +0 -9
- package/dist/collections/reserved-field-names.d.ts +0 -9
- package/dist/entries/entry-base.d.cts +0 -31
- package/dist/entries/entry-base.d.ts +0 -31
- package/dist/entries/entry-mapper.d.cts +0 -13
- package/dist/entries/entry-mapper.d.ts +0 -13
- package/dist/entries/entry-payload.d.cts +0 -12
- package/dist/entries/entry-payload.d.ts +0 -12
- package/dist/entries/resolved-entry.d.cts +0 -11
- package/dist/entries/resolved-entry.d.ts +0 -11
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four keys silo puts on every entry alongside the author's own fields.
|
|
3
|
+
*
|
|
4
|
+
* `rev` is here because `replace()` and `delete()` require the revision the
|
|
5
|
+
* caller expects and a mismatch is a `409`, so the number has to survive the
|
|
6
|
+
* trip from a read to a write. The timestamps are ISO-8601 strings rather than
|
|
7
|
+
* `Date`s, and `created_at` keeps the wire's spelling, because a row read from
|
|
8
|
+
* one call and handed to the next unchanged is worth more than a prettier one.
|
|
9
|
+
*
|
|
10
|
+
* No field can collide with these: silo refuses a schema declaring one and an
|
|
11
|
+
* entry carrying one (D62).
|
|
12
|
+
*/
|
|
13
|
+
export interface EntryEnvelope {
|
|
14
|
+
id: string;
|
|
15
|
+
rev: number;
|
|
16
|
+
created_at: string;
|
|
17
|
+
updated_at: string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RequestOptions } from "../request-options.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* What every read accepts on top of the cancellation options.
|
|
4
|
+
*
|
|
5
|
+
* `variables: "raw"` answers the `{{NAME}}` templates as stored instead of
|
|
6
|
+
* what they resolve to. An editor wants exactly that: seeding a form with a
|
|
7
|
+
* resolved value and saving it back replaces the reference somebody typed with
|
|
8
|
+
* a snapshot of what it meant in one environment on one day, and a template
|
|
9
|
+
* cannot be recovered from its substitution (D57).
|
|
10
|
+
*
|
|
11
|
+
* Reads resolve by default, because an application reading content should not
|
|
12
|
+
* have to opt in to a usable value.
|
|
13
|
+
*/
|
|
14
|
+
export interface EntryReadOptions extends RequestOptions {
|
|
15
|
+
variables?: "raw";
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RequestOptions } from "../request-options.js";
|
|
2
|
+
/**
|
|
3
|
+
* What every read accepts on top of the cancellation options.
|
|
4
|
+
*
|
|
5
|
+
* `variables: "raw"` answers the `{{NAME}}` templates as stored instead of
|
|
6
|
+
* what they resolve to. An editor wants exactly that: seeding a form with a
|
|
7
|
+
* resolved value and saving it back replaces the reference somebody typed with
|
|
8
|
+
* a snapshot of what it meant in one environment on one day, and a template
|
|
9
|
+
* cannot be recovered from its substitution (D57).
|
|
10
|
+
*
|
|
11
|
+
* Reads resolve by default, because an application reading content should not
|
|
12
|
+
* have to opt in to a usable value.
|
|
13
|
+
*/
|
|
14
|
+
export interface EntryReadOptions extends RequestOptions {
|
|
15
|
+
variables?: "raw";
|
|
16
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ScopeReference } from "../scope/scope-reference.cjs";
|
|
2
|
+
import type { Entry } from "./entry.cjs";
|
|
3
3
|
import type { EntryListQuery } from "./entry-list-query.cjs";
|
|
4
4
|
import { EntryPage } from "./entry-page.cjs";
|
|
5
5
|
import { EntryPageStream } from "./entry-page-stream.cjs";
|
|
6
|
-
import type {
|
|
6
|
+
import type { EntryReadOptions } from "./entry-read-options.cjs";
|
|
7
7
|
import { EntryStream } from "./entry-stream.cjs";
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* The four reads of one collection: one entry, one page, every entry, every
|
|
10
|
+
* page.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Nothing is mapped on the way through — an answer is the wire's own row
|
|
13
|
+
* (D62) — so what this class actually owns is the paging the four share and
|
|
14
|
+
* the one place `variables` is turned into a query parameter.
|
|
14
15
|
*/
|
|
15
|
-
export declare class EntryReader<
|
|
16
|
-
private readonly
|
|
17
|
-
private readonly
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
list(query?: EntryListQuery, options?: RequestOptions): Promise<EntryPage<Row>>;
|
|
16
|
+
export declare class EntryReader<Fields> {
|
|
17
|
+
private readonly scope;
|
|
18
|
+
private readonly collection;
|
|
19
|
+
constructor(scope: ScopeReference, collection: string);
|
|
20
|
+
get(id: string, options?: EntryReadOptions): Promise<Entry<Fields>>;
|
|
21
|
+
list(query?: EntryListQuery, options?: EntryReadOptions): Promise<EntryPage<Entry<Fields>>>;
|
|
22
22
|
/** Every matching entry, one at a time, `limit` rows per request. */
|
|
23
|
-
all(query?: EntryListQuery, options?:
|
|
23
|
+
all(query?: EntryListQuery, options?: EntryReadOptions): EntryStream<Entry<Fields>>;
|
|
24
24
|
/** Every matching page, one at a time. */
|
|
25
|
-
pages(query?: EntryListQuery, options?:
|
|
25
|
+
pages(query?: EntryListQuery, options?: EntryReadOptions): EntryPageStream<Entry<Fields>>;
|
|
26
26
|
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ScopeReference } from "../scope/scope-reference.js";
|
|
2
|
+
import type { Entry } from "./entry.js";
|
|
3
3
|
import type { EntryListQuery } from "./entry-list-query.js";
|
|
4
4
|
import { EntryPage } from "./entry-page.js";
|
|
5
5
|
import { EntryPageStream } from "./entry-page-stream.js";
|
|
6
|
-
import type {
|
|
6
|
+
import type { EntryReadOptions } from "./entry-read-options.js";
|
|
7
7
|
import { EntryStream } from "./entry-stream.js";
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* The four reads of one collection: one entry, one page, every entry, every
|
|
10
|
+
* page.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* Nothing is mapped on the way through — an answer is the wire's own row
|
|
13
|
+
* (D62) — so what this class actually owns is the paging the four share and
|
|
14
|
+
* the one place `variables` is turned into a query parameter.
|
|
14
15
|
*/
|
|
15
|
-
export declare class EntryReader<
|
|
16
|
-
private readonly
|
|
17
|
-
private readonly
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
list(query?: EntryListQuery, options?: RequestOptions): Promise<EntryPage<Row>>;
|
|
16
|
+
export declare class EntryReader<Fields> {
|
|
17
|
+
private readonly scope;
|
|
18
|
+
private readonly collection;
|
|
19
|
+
constructor(scope: ScopeReference, collection: string);
|
|
20
|
+
get(id: string, options?: EntryReadOptions): Promise<Entry<Fields>>;
|
|
21
|
+
list(query?: EntryListQuery, options?: EntryReadOptions): Promise<EntryPage<Entry<Fields>>>;
|
|
22
22
|
/** Every matching entry, one at a time, `limit` rows per request. */
|
|
23
|
-
all(query?: EntryListQuery, options?:
|
|
23
|
+
all(query?: EntryListQuery, options?: EntryReadOptions): EntryStream<Entry<Fields>>;
|
|
24
24
|
/** Every matching page, one at a time. */
|
|
25
|
-
pages(query?: EntryListQuery, options?:
|
|
25
|
+
pages(query?: EntryListQuery, options?: EntryReadOptions): EntryPageStream<Entry<Fields>>;
|
|
26
26
|
}
|
package/dist/entries/entry.d.cts
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { ResolvedEntry } from "./resolved-entry.cjs";
|
|
1
|
+
import type { EntryEnvelope } from "./entry-envelope.cjs";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* One entry exactly as the API answers it: the author's fields and the
|
|
4
|
+
* envelope in one flat object, with nothing renamed, nested or wrapped.
|
|
5
|
+
*
|
|
6
|
+
* This is a plain value. It carries no transport, no scope and no methods, so
|
|
7
|
+
* it logs as its own contents, survives `structuredClone`, and drops into a
|
|
8
|
+
* store or React state as-is. Writes go through the collection —
|
|
9
|
+
* `posts.replace(id, rev, fields)`, `posts.delete(id, rev)` — where the
|
|
10
|
+
* revision being sent is visible at the call site instead of hidden inside an
|
|
11
|
+
* object (D62).
|
|
7
12
|
*/
|
|
8
|
-
export
|
|
9
|
-
rev: number;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
updatedAt: Date;
|
|
12
|
-
fields: Fields;
|
|
13
|
-
private saving;
|
|
14
|
-
/**
|
|
15
|
-
* Sends `PUT` with the rev this instance holds, adopts the rev and
|
|
16
|
-
* timestamps the response answers, and mutates in place. A second
|
|
17
|
-
* overlapping call on the same instance is refused locally — it would
|
|
18
|
-
* send a rev already known to be stale.
|
|
19
|
-
*/
|
|
20
|
-
save(options?: RequestOptions): Promise<this>;
|
|
21
|
-
/** Re-reads this entry raw, and replaces `fields`, `rev` and the
|
|
22
|
-
* timestamps in place — what a `ConflictError` from `save()` calls for. */
|
|
23
|
-
refresh(options?: RequestOptions): Promise<this>;
|
|
24
|
-
private adopt;
|
|
25
|
-
}
|
|
13
|
+
export type Entry<Fields = Record<string, unknown>> = Fields & EntryEnvelope;
|
package/dist/entries/entry.d.ts
CHANGED
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { ResolvedEntry } from "./resolved-entry.js";
|
|
1
|
+
import type { EntryEnvelope } from "./entry-envelope.js";
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
3
|
+
* One entry exactly as the API answers it: the author's fields and the
|
|
4
|
+
* envelope in one flat object, with nothing renamed, nested or wrapped.
|
|
5
|
+
*
|
|
6
|
+
* This is a plain value. It carries no transport, no scope and no methods, so
|
|
7
|
+
* it logs as its own contents, survives `structuredClone`, and drops into a
|
|
8
|
+
* store or React state as-is. Writes go through the collection —
|
|
9
|
+
* `posts.replace(id, rev, fields)`, `posts.delete(id, rev)` — where the
|
|
10
|
+
* revision being sent is visible at the call site instead of hidden inside an
|
|
11
|
+
* object (D62).
|
|
7
12
|
*/
|
|
8
|
-
export
|
|
9
|
-
rev: number;
|
|
10
|
-
createdAt: Date;
|
|
11
|
-
updatedAt: Date;
|
|
12
|
-
fields: Fields;
|
|
13
|
-
private saving;
|
|
14
|
-
/**
|
|
15
|
-
* Sends `PUT` with the rev this instance holds, adopts the rev and
|
|
16
|
-
* timestamps the response answers, and mutates in place. A second
|
|
17
|
-
* overlapping call on the same instance is refused locally — it would
|
|
18
|
-
* send a rev already known to be stale.
|
|
19
|
-
*/
|
|
20
|
-
save(options?: RequestOptions): Promise<this>;
|
|
21
|
-
/** Re-reads this entry raw, and replaces `fields`, `rev` and the
|
|
22
|
-
* timestamps in place — what a `ConflictError` from `save()` calls for. */
|
|
23
|
-
refresh(options?: RequestOptions): Promise<this>;
|
|
24
|
-
private adopt;
|
|
25
|
-
}
|
|
13
|
+
export type Entry<Fields = Record<string, unknown>> = Fields & EntryEnvelope;
|
package/dist/index.cjs
CHANGED
|
@@ -53,8 +53,6 @@ __export(exports_src, {
|
|
|
53
53
|
Search: () => Search,
|
|
54
54
|
RowStream: () => RowStream,
|
|
55
55
|
RouteInventory: () => RouteInventory,
|
|
56
|
-
ResolvedEntry: () => ResolvedEntry,
|
|
57
|
-
ReservedFieldNames: () => ReservedFieldNames,
|
|
58
56
|
RequestAbortedError: () => RequestAbortedError,
|
|
59
57
|
RenameReport: () => RenameReport,
|
|
60
58
|
Projects: () => Projects,
|
|
@@ -90,8 +88,6 @@ __export(exports_src, {
|
|
|
90
88
|
EntryReader: () => EntryReader,
|
|
91
89
|
EntryPageStream: () => EntryPageStream,
|
|
92
90
|
EntryPage: () => EntryPage,
|
|
93
|
-
EntryBase: () => EntryBase,
|
|
94
|
-
Entry: () => Entry,
|
|
95
91
|
ConflictError: () => ConflictError,
|
|
96
92
|
Collections: () => Collections,
|
|
97
93
|
CollectionSchema: () => CollectionSchema,
|
|
@@ -779,96 +775,6 @@ class ProjectVariables {
|
|
|
779
775
|
}
|
|
780
776
|
}
|
|
781
777
|
|
|
782
|
-
// src/entries/entry-mapper.ts
|
|
783
|
-
class EntryMapper {
|
|
784
|
-
static fieldsOf(payload) {
|
|
785
|
-
const { id: _id, rev: _rev, created_at: _createdAt, updated_at: _updatedAt, ...fields } = payload;
|
|
786
|
-
return fields;
|
|
787
|
-
}
|
|
788
|
-
static toPayload(id, rev, fields, createdAt, updatedAt) {
|
|
789
|
-
return {
|
|
790
|
-
id,
|
|
791
|
-
rev,
|
|
792
|
-
...fields,
|
|
793
|
-
created_at: createdAt.toISOString(),
|
|
794
|
-
updated_at: updatedAt.toISOString()
|
|
795
|
-
};
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// src/entries/entry-base.ts
|
|
800
|
-
class EntryBase {
|
|
801
|
-
context;
|
|
802
|
-
id;
|
|
803
|
-
rev;
|
|
804
|
-
createdAt;
|
|
805
|
-
updatedAt;
|
|
806
|
-
fields;
|
|
807
|
-
constructor(context, payload) {
|
|
808
|
-
this.context = context;
|
|
809
|
-
this.id = String(payload.id);
|
|
810
|
-
this.rev = Number(payload.rev);
|
|
811
|
-
this.createdAt = new Date(payload.created_at);
|
|
812
|
-
this.updatedAt = new Date(payload.updated_at);
|
|
813
|
-
this.fields = EntryMapper.fieldsOf(payload);
|
|
814
|
-
}
|
|
815
|
-
toJSON() {
|
|
816
|
-
return EntryMapper.toPayload(this.id, this.rev, this.fields, this.createdAt, this.updatedAt);
|
|
817
|
-
}
|
|
818
|
-
async delete(options = {}) {
|
|
819
|
-
await this.context.transport.empty({
|
|
820
|
-
method: "DELETE",
|
|
821
|
-
path: ApiPath.entry(this.context.project, this.context.environment, this.context.collection, this.id),
|
|
822
|
-
query: { rev: this.rev },
|
|
823
|
-
...options
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
|
|
828
|
-
// src/entries/resolved-entry.ts
|
|
829
|
-
class ResolvedEntry extends EntryBase {
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// src/entries/entry.ts
|
|
833
|
-
class Entry extends ResolvedEntry {
|
|
834
|
-
saving = false;
|
|
835
|
-
async save(options = {}) {
|
|
836
|
-
if (this.saving) {
|
|
837
|
-
throw new Error(`cannot save entry "${this.id}": a previous save() on this instance has not finished yet`);
|
|
838
|
-
}
|
|
839
|
-
this.saving = true;
|
|
840
|
-
try {
|
|
841
|
-
const payload = await this.context.transport.json({
|
|
842
|
-
method: "PUT",
|
|
843
|
-
path: ApiPath.entry(this.context.project, this.context.environment, this.context.collection, this.id),
|
|
844
|
-
query: { rev: this.rev, variables: "raw" },
|
|
845
|
-
body: this.fields,
|
|
846
|
-
...options
|
|
847
|
-
});
|
|
848
|
-
this.adopt(payload);
|
|
849
|
-
return this;
|
|
850
|
-
} finally {
|
|
851
|
-
this.saving = false;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
async refresh(options = {}) {
|
|
855
|
-
const payload = await this.context.transport.json({
|
|
856
|
-
method: "GET",
|
|
857
|
-
path: ApiPath.entry(this.context.project, this.context.environment, this.context.collection, this.id),
|
|
858
|
-
query: { variables: "raw" },
|
|
859
|
-
...options
|
|
860
|
-
});
|
|
861
|
-
this.adopt(payload);
|
|
862
|
-
return this;
|
|
863
|
-
}
|
|
864
|
-
adopt(payload) {
|
|
865
|
-
this.rev = Number(payload.rev);
|
|
866
|
-
this.createdAt = new Date(payload.created_at);
|
|
867
|
-
this.updatedAt = new Date(payload.updated_at);
|
|
868
|
-
this.fields = EntryMapper.fieldsOf(payload);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
|
|
872
778
|
// src/transport/page-payload.ts
|
|
873
779
|
class PagePayload {
|
|
874
780
|
static read(body) {
|
|
@@ -929,40 +835,39 @@ class EntryStream extends RowStream {
|
|
|
929
835
|
|
|
930
836
|
// src/entries/entry-reader.ts
|
|
931
837
|
class EntryReader {
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
this.
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
const payload = await this.context.transport.json({
|
|
838
|
+
scope;
|
|
839
|
+
collection;
|
|
840
|
+
constructor(scope, collection) {
|
|
841
|
+
this.scope = scope;
|
|
842
|
+
this.collection = collection;
|
|
843
|
+
}
|
|
844
|
+
get(id, options = {}) {
|
|
845
|
+
const { variables, ...request } = options;
|
|
846
|
+
return this.scope.transport.json({
|
|
942
847
|
method: "GET",
|
|
943
|
-
path: ApiPath.entry(this.
|
|
944
|
-
query: { variables
|
|
945
|
-
...
|
|
848
|
+
path: ApiPath.entry(this.scope.project, this.scope.environment, this.collection, id),
|
|
849
|
+
query: { variables },
|
|
850
|
+
...request
|
|
946
851
|
});
|
|
947
|
-
return this.wrap(payload);
|
|
948
852
|
}
|
|
949
853
|
async list(query = {}, options = {}) {
|
|
854
|
+
const { variables, ...request } = options;
|
|
950
855
|
const loader = (window2) => this.list({ ...query, limit: window2.limit, offset: window2.offset }, options);
|
|
951
|
-
const body = await this.
|
|
856
|
+
const body = await this.scope.transport.json({
|
|
952
857
|
method: "GET",
|
|
953
|
-
path: ApiPath.entries(this.
|
|
858
|
+
path: ApiPath.entries(this.scope.project, this.scope.environment, this.collection),
|
|
954
859
|
query: {
|
|
955
860
|
limit: query.limit,
|
|
956
861
|
offset: query.offset,
|
|
957
862
|
filter: query.where?.toJSON(),
|
|
958
863
|
sort: query.sort === undefined ? undefined : String(query.sort),
|
|
959
|
-
variables
|
|
864
|
+
variables
|
|
960
865
|
},
|
|
961
|
-
...
|
|
866
|
+
...request
|
|
962
867
|
});
|
|
963
868
|
const page = PagePayload.read(body);
|
|
964
869
|
const window = new PageWindow(page.limit ?? query.limit ?? 50, page.offset ?? query.offset ?? 0);
|
|
965
|
-
return new EntryPage(page.rows
|
|
870
|
+
return new EntryPage(page.rows, page.total, window, loader);
|
|
966
871
|
}
|
|
967
872
|
all(query = {}, options = {}) {
|
|
968
873
|
const loader = async (window) => {
|
|
@@ -1136,15 +1041,15 @@ class Search {
|
|
|
1136
1041
|
const window = new PageWindow(page.limit ?? query.limit ?? 50, page.offset ?? query.offset ?? 0);
|
|
1137
1042
|
const truncated = body.truncated === true;
|
|
1138
1043
|
const engine = body.engine;
|
|
1139
|
-
const hits = page.rows.map((hit) =>
|
|
1044
|
+
const hits = page.rows.map((hit) => Search.toHit(hit));
|
|
1140
1045
|
return new SearchPage(hits, page.total, window, truncated, engine, loader);
|
|
1141
1046
|
}
|
|
1142
|
-
toHit(payload) {
|
|
1047
|
+
static toHit(payload) {
|
|
1143
1048
|
return {
|
|
1144
1049
|
project: payload.project,
|
|
1145
1050
|
environment: payload.env,
|
|
1146
1051
|
collection: payload.collection,
|
|
1147
|
-
entry:
|
|
1052
|
+
entry: payload.entry,
|
|
1148
1053
|
snippets: payload.snippets
|
|
1149
1054
|
};
|
|
1150
1055
|
}
|
|
@@ -1207,36 +1112,24 @@ class CollectionHandle {
|
|
|
1207
1112
|
name;
|
|
1208
1113
|
filter = new TypedFilter;
|
|
1209
1114
|
schema;
|
|
1210
|
-
|
|
1211
|
-
context;
|
|
1212
|
-
resolved;
|
|
1115
|
+
reader;
|
|
1213
1116
|
constructor(scope, name) {
|
|
1214
1117
|
this.scope = scope;
|
|
1215
1118
|
this.name = name;
|
|
1216
1119
|
this.schema = new CollectionSchema(scope, name);
|
|
1217
|
-
this.
|
|
1218
|
-
transport: scope.transport,
|
|
1219
|
-
project: scope.project,
|
|
1220
|
-
environment: scope.environment,
|
|
1221
|
-
collection: name
|
|
1222
|
-
};
|
|
1223
|
-
this.resolved = new EntryReader(this.context, undefined, (payload) => new ResolvedEntry(this.context, payload));
|
|
1224
|
-
this.editable = new EntryReader(this.context, "raw", (payload) => new Entry(this.context, payload));
|
|
1120
|
+
this.reader = new EntryReader(scope, name);
|
|
1225
1121
|
}
|
|
1226
1122
|
get(id, options = {}) {
|
|
1227
|
-
return this.
|
|
1228
|
-
}
|
|
1229
|
-
edit(id, options = {}) {
|
|
1230
|
-
return this.editable.get(id, options);
|
|
1123
|
+
return this.reader.get(id, options);
|
|
1231
1124
|
}
|
|
1232
1125
|
list(query = {}, options = {}) {
|
|
1233
|
-
return this.
|
|
1126
|
+
return this.reader.list(query, options);
|
|
1234
1127
|
}
|
|
1235
1128
|
all(query = {}, options = {}) {
|
|
1236
|
-
return this.
|
|
1129
|
+
return this.reader.all(query, options);
|
|
1237
1130
|
}
|
|
1238
1131
|
pages(query = {}, options = {}) {
|
|
1239
|
-
return this.
|
|
1132
|
+
return this.reader.pages(query, options);
|
|
1240
1133
|
}
|
|
1241
1134
|
create(fields, options = {}) {
|
|
1242
1135
|
return this.write("POST", ApiPath.entries(this.scope.project, this.scope.environment, this.name), fields, undefined, options);
|
|
@@ -1266,23 +1159,14 @@ class CollectionHandle {
|
|
|
1266
1159
|
});
|
|
1267
1160
|
return RenameReport.fromWire(payload);
|
|
1268
1161
|
}
|
|
1269
|
-
|
|
1270
|
-
|
|
1162
|
+
write(method, path, fields, rev, options) {
|
|
1163
|
+
return this.scope.transport.json({
|
|
1271
1164
|
method,
|
|
1272
1165
|
path,
|
|
1273
1166
|
query: { rev, variables: "raw" },
|
|
1274
1167
|
body: fields,
|
|
1275
1168
|
...options
|
|
1276
1169
|
});
|
|
1277
|
-
return new Entry(this.context, payload);
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
|
-
// src/collections/reserved-field-names.ts
|
|
1282
|
-
class ReservedFieldNames {
|
|
1283
|
-
static all = ["id", "rev", "seq", "created_at", "updated_at"];
|
|
1284
|
-
static isReserved(name) {
|
|
1285
|
-
return ReservedFieldNames.all.includes(name);
|
|
1286
1170
|
}
|
|
1287
1171
|
}
|
|
1288
1172
|
|
|
@@ -1301,7 +1185,6 @@ class Collections {
|
|
|
1301
1185
|
return body.items.map(Collections.toSummary);
|
|
1302
1186
|
}
|
|
1303
1187
|
async create(name, schema, options = {}) {
|
|
1304
|
-
Collections.warnOnReservedFields(schema);
|
|
1305
1188
|
return this.scope.transport.json({
|
|
1306
1189
|
method: "POST",
|
|
1307
1190
|
path: ApiPath.collections(this.scope.project, this.scope.environment),
|
|
@@ -1319,13 +1202,6 @@ class Collections {
|
|
|
1319
1202
|
updatedAt: new Date(payload.updated_at)
|
|
1320
1203
|
};
|
|
1321
1204
|
}
|
|
1322
|
-
static warnOnReservedFields(schema) {
|
|
1323
|
-
for (const name of Object.keys(schema.properties ?? {})) {
|
|
1324
|
-
if (ReservedFieldNames.isReserved(name)) {
|
|
1325
|
-
console.warn(`@org-quicko/silo-client: collection schema declares reserved field "${name}", which the server never returns`);
|
|
1326
|
-
}
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
1205
|
}
|
|
1330
1206
|
|
|
1331
1207
|
// src/variables/environment-variables.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -21,19 +21,17 @@ export type { DeleteOptions } from "./scope/delete-options.cjs";
|
|
|
21
21
|
export { Collections } from "./collections/collections.cjs";
|
|
22
22
|
export { CollectionHandle } from "./collections/collection-handle.cjs";
|
|
23
23
|
export { CollectionSchema } from "./collections/collection-schema.cjs";
|
|
24
|
-
export { ReservedFieldNames } from "./collections/reserved-field-names.cjs";
|
|
25
24
|
export type { CollectionSummary } from "./collections/collection-summary.cjs";
|
|
26
25
|
export type { CollectionDefinition } from "./collections/collection-definition.cjs";
|
|
27
26
|
export type { JsonSchema } from "./collections/json-schema.cjs";
|
|
28
|
-
export { EntryBase } from "./entries/entry-base.cjs";
|
|
29
|
-
export { ResolvedEntry } from "./entries/resolved-entry.cjs";
|
|
30
|
-
export { Entry } from "./entries/entry.cjs";
|
|
31
27
|
export { EntryPage } from "./entries/entry-page.cjs";
|
|
32
28
|
export { EntryStream } from "./entries/entry-stream.cjs";
|
|
33
29
|
export { EntryPageStream } from "./entries/entry-page-stream.cjs";
|
|
34
30
|
export { EntryReader } from "./entries/entry-reader.cjs";
|
|
31
|
+
export type { Entry } from "./entries/entry.cjs";
|
|
32
|
+
export type { EntryEnvelope } from "./entries/entry-envelope.cjs";
|
|
35
33
|
export type { EntryListQuery } from "./entries/entry-list-query.cjs";
|
|
36
|
-
export type {
|
|
34
|
+
export type { EntryReadOptions } from "./entries/entry-read-options.cjs";
|
|
37
35
|
export { Filter } from "./query/filter.cjs";
|
|
38
36
|
export { TypedFilter } from "./query/typed-filter.cjs";
|
|
39
37
|
export { FilterField } from "./query/filter-field.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -21,19 +21,17 @@ export type { DeleteOptions } from "./scope/delete-options.js";
|
|
|
21
21
|
export { Collections } from "./collections/collections.js";
|
|
22
22
|
export { CollectionHandle } from "./collections/collection-handle.js";
|
|
23
23
|
export { CollectionSchema } from "./collections/collection-schema.js";
|
|
24
|
-
export { ReservedFieldNames } from "./collections/reserved-field-names.js";
|
|
25
24
|
export type { CollectionSummary } from "./collections/collection-summary.js";
|
|
26
25
|
export type { CollectionDefinition } from "./collections/collection-definition.js";
|
|
27
26
|
export type { JsonSchema } from "./collections/json-schema.js";
|
|
28
|
-
export { EntryBase } from "./entries/entry-base.js";
|
|
29
|
-
export { ResolvedEntry } from "./entries/resolved-entry.js";
|
|
30
|
-
export { Entry } from "./entries/entry.js";
|
|
31
27
|
export { EntryPage } from "./entries/entry-page.js";
|
|
32
28
|
export { EntryStream } from "./entries/entry-stream.js";
|
|
33
29
|
export { EntryPageStream } from "./entries/entry-page-stream.js";
|
|
34
30
|
export { EntryReader } from "./entries/entry-reader.js";
|
|
31
|
+
export type { Entry } from "./entries/entry.js";
|
|
32
|
+
export type { EntryEnvelope } from "./entries/entry-envelope.js";
|
|
35
33
|
export type { EntryListQuery } from "./entries/entry-list-query.js";
|
|
36
|
-
export type {
|
|
34
|
+
export type { EntryReadOptions } from "./entries/entry-read-options.js";
|
|
37
35
|
export { Filter } from "./query/filter.js";
|
|
38
36
|
export { TypedFilter } from "./query/typed-filter.js";
|
|
39
37
|
export { FilterField } from "./query/filter-field.js";
|