teamplay 0.5.0-alpha.30 → 0.5.0-alpha.31
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/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/connect/index.d.ts +1 -1
- package/dist/connect/index.js +6 -2
- package/dist/connect/offline/index.d.ts +1 -1
- package/dist/connect/offline/index.js +8 -4
- package/dist/connect/offline/react-native.d.ts +1 -1
- package/dist/connect/offline/web.d.ts +1 -1
- package/dist/connect/test.d.ts +1 -1
- package/dist/connect/test.js +5 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/orm/Compat/SignalCompat.js +0 -1
- package/dist/orm/SignalBase.d.ts +1 -1
- package/dist/orm/SignalBase.js +8 -4
- package/dist/orm/idFields.d.ts +10 -1
- package/dist/orm/idFields.js +102 -14
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -1
- package/package.json +7 -2
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from "./orm/idFields.js";
|
package/dist/connect/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function connect(options
|
|
1
|
+
export default function connect(options?: {}): void;
|
package/dist/connect/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import Socket from '@teamplay/channel';
|
|
2
2
|
import Connection from './sharedbConnection.cjs';
|
|
3
3
|
import { connection, setConnection } from "../orm/connection.js";
|
|
4
|
-
|
|
4
|
+
import { configureTeamplay } from "../config.js";
|
|
5
|
+
export default function connect(options = {}) {
|
|
6
|
+
const { idFields, ...socketOptions } = options || {};
|
|
7
|
+
if (idFields !== undefined)
|
|
8
|
+
configureTeamplay({ idFields });
|
|
5
9
|
if (connection)
|
|
6
10
|
return;
|
|
7
|
-
const socket = new Socket(
|
|
11
|
+
const socket = new Socket(socketOptions);
|
|
8
12
|
setConnection(new Connection(socket));
|
|
9
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function createConnectWithPersistence({ storage, createPubsub }?: {}): () => Promise<void>;
|
|
1
|
+
export default function createConnectWithPersistence({ storage, createPubsub }?: {}): (options?: {}) => Promise<void>;
|
|
@@ -3,21 +3,25 @@
|
|
|
3
3
|
import ShareDbMingo from '@startupjs/sharedb-mingo-memory';
|
|
4
4
|
import ShareBackend from 'sharedb';
|
|
5
5
|
import { connection, setConnection } from "../../orm/connection.js";
|
|
6
|
+
import { configureTeamplay } from "../../config.js";
|
|
6
7
|
const STORAGE_NAMESPACE = 'teamplay-offline';
|
|
7
8
|
const DOCS_PREFIX = `${STORAGE_NAMESPACE}:docs:`;
|
|
8
9
|
const LAST_OP_PREFIX = `${STORAGE_NAMESPACE}:last-op:`;
|
|
9
10
|
export default function createConnectWithPersistence({ storage, createPubsub } = {}) {
|
|
10
11
|
if (!storage)
|
|
11
12
|
throw new Error('[connect-offline] storage is required');
|
|
12
|
-
return async function connect() {
|
|
13
|
+
return async function connect(options = {}) {
|
|
14
|
+
const { idFields } = options || {};
|
|
15
|
+
if (idFields !== undefined)
|
|
16
|
+
configureTeamplay({ idFields });
|
|
13
17
|
if (connection)
|
|
14
18
|
return;
|
|
15
19
|
const db = new ShareDbMingo();
|
|
16
|
-
const
|
|
20
|
+
const backendOptions = { db };
|
|
17
21
|
const { pubsub } = (await init(db, storage, createPubsub)) || {};
|
|
18
22
|
if (pubsub)
|
|
19
|
-
|
|
20
|
-
const backend = new ShareBackend(
|
|
23
|
+
backendOptions.pubsub = pubsub;
|
|
24
|
+
const backend = new ShareBackend(backendOptions);
|
|
21
25
|
setConnection(backend.connect());
|
|
22
26
|
};
|
|
23
27
|
}
|
|
@@ -3,7 +3,7 @@ export namespace storage {
|
|
|
3
3
|
export { setItem };
|
|
4
4
|
export { iterate };
|
|
5
5
|
}
|
|
6
|
-
declare const _default: () => Promise<void>;
|
|
6
|
+
declare const _default: (options?: {}) => Promise<void>;
|
|
7
7
|
export default _default;
|
|
8
8
|
declare function getItem(key: any): Promise<any>;
|
|
9
9
|
declare function setItem(key: any, value: any): Promise<any>;
|
|
@@ -4,6 +4,6 @@ export namespace storage {
|
|
|
4
4
|
function setItem(key: any, value: any): Promise<any>;
|
|
5
5
|
function iterate(iterator: any): Promise<any>;
|
|
6
6
|
}
|
|
7
|
-
declare const _default: () => Promise<void>;
|
|
7
|
+
declare const _default: (options?: {}) => Promise<void>;
|
|
8
8
|
export default _default;
|
|
9
9
|
import SharedbCrosstabPubsub from '../lib/sharedb-crosstab-pubsub.cjs';
|
package/dist/connect/test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function connect(): void;
|
|
1
|
+
export default function connect(options?: {}): void;
|
package/dist/connect/test.js
CHANGED
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import ShareDbMingo from '@startupjs/sharedb-mingo-memory';
|
|
5
5
|
import ShareBackend from 'sharedb';
|
|
6
6
|
import { connection, setConnection } from "../orm/connection.js";
|
|
7
|
-
|
|
7
|
+
import { configureTeamplay } from "../config.js";
|
|
8
|
+
export default function connect(options = {}) {
|
|
9
|
+
const { idFields } = options || {};
|
|
10
|
+
if (idFields !== undefined)
|
|
11
|
+
configureTeamplay({ idFields });
|
|
8
12
|
if (connection)
|
|
9
13
|
return;
|
|
10
14
|
const backend = new ShareBackend({ db: new ShareDbMingo() });
|
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,8 @@ export { emit, useOn, useEmit } from './orm/Compat/eventsCompat.js';
|
|
|
62
62
|
export { useDidUpdate, useOnce, useSyncEffect } from './react/helpers.js';
|
|
63
63
|
export { connection, setConnection, getConnection, getDefaultFetchOnly, setDefaultFetchOnly, publicOnly, setPublicOnly } from './orm/connection.js';
|
|
64
64
|
export type { TeamplayConnection, TeamplayShareDoc } from './orm/connection.js';
|
|
65
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from './config.js';
|
|
66
|
+
export type { IdField, IdFields, TeamplayRuntimeConfig } from './config.js';
|
|
65
67
|
export { getSubscriptionGcDelay, setSubscriptionGcDelay } from './orm/subscriptionGcDelay.js';
|
|
66
68
|
export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from './react/helpers.js';
|
|
67
69
|
export { GUID_PATTERN, defineSchema, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema';
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ export const observer = runtimeObserver;
|
|
|
21
21
|
export { emit, useOn, useEmit } from './orm/Compat/eventsCompat.js';
|
|
22
22
|
export { useDidUpdate, useOnce, useSyncEffect } from "./react/helpers.js";
|
|
23
23
|
export { connection, setConnection, getConnection, getDefaultFetchOnly, setDefaultFetchOnly, publicOnly, setPublicOnly } from "./orm/connection.js";
|
|
24
|
+
export { TEAMPLAY_RUNTIME_CONFIG_SYMBOL, configureTeamplay, getTeamplayConfig, getDefaultIdFields, setDefaultIdFields } from "./config.js";
|
|
24
25
|
export { getSubscriptionGcDelay, setSubscriptionGcDelay } from "./orm/subscriptionGcDelay.js";
|
|
25
26
|
export { useId, useNow, useScheduleUpdate, useTriggerUpdate } from "./react/helpers.js";
|
|
26
27
|
export { GUID_PATTERN, defineSchema, hasMany, hasOne, hasManyFlags, belongsTo, pickFormFields } from '@teamplay/schema';
|
|
@@ -18,7 +18,6 @@ import universal$ from "../../react/universal$.js";
|
|
|
18
18
|
import { getRootContext } from "../rootContext.js";
|
|
19
19
|
import { arrayInsertPrivateData, arrayMovePrivateData, arrayPopPrivateData, arrayPushPrivateData, arrayRemovePrivateData, arrayShiftPrivateData, arrayUnshiftPrivateData, delPrivateData, setReplacePrivateData, stringInsertPrivateData, stringRemovePrivateData } from '../privateData.js';
|
|
20
20
|
class SignalCompat extends Signal {
|
|
21
|
-
static ID_FIELDS = ['_id'];
|
|
22
21
|
static [GETTERS] = DEFAULT_GETTERS;
|
|
23
22
|
path() {
|
|
24
23
|
if (arguments.length > 0)
|
package/dist/orm/SignalBase.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ARRAY_METHOD, DEFAULT_GETTERS, GET, GETTERS, SEGMENTS } from './signalS
|
|
|
2
2
|
export { SEGMENTS, ARRAY_METHOD, GET, GETTERS, DEFAULT_GETTERS };
|
|
3
3
|
export declare class Signal<TValue = unknown> extends Function {
|
|
4
4
|
/** Fields that are treated as document ids and mirror the document id segment. */
|
|
5
|
-
static ID_FIELDS:
|
|
5
|
+
static get ID_FIELDS(): import("./idFields.js").IdFields;
|
|
6
6
|
/** Method names that keep method binding priority over child signal dot access. */
|
|
7
7
|
static [GETTERS]: string[];
|
|
8
8
|
/** Association metadata registered for this model class. */
|
package/dist/orm/SignalBase.js
CHANGED
|
@@ -21,7 +21,7 @@ import { docSubscriptions } from './Doc.js';
|
|
|
21
21
|
import { IS_QUERY, HASH, QUERIES } from './Query.js';
|
|
22
22
|
import { AGGREGATIONS, IS_AGGREGATION, getAggregationCollectionName, getAggregationDocId } from './Aggregation.js';
|
|
23
23
|
import { ROOT_FUNCTION, ROOT_ID, closeRootSignal, getRoot } from "./Root.js";
|
|
24
|
-
import {
|
|
24
|
+
import { getDefaultIdFields, getIdFieldsForSegments, isIdFieldPath, isPlainObject, isPublicDocPath, normalizeIdFields, prepareAddPayload, resolveAddDocId } from "./idFields.js";
|
|
25
25
|
import { isCompatEnv } from './compatEnv.js';
|
|
26
26
|
import { resolveRefSegmentsSafe, resolveRefSignalSafe } from './Compat/refFallback.js';
|
|
27
27
|
import { compatStartOnRoot, compatStopOnRoot, joinScopePath } from './Compat/startStopCompat.js';
|
|
@@ -91,7 +91,9 @@ const SIGNAL_VALUE_MUTATION_CONTEXT = {
|
|
|
91
91
|
};
|
|
92
92
|
export class Signal extends Function {
|
|
93
93
|
/** Fields that are treated as document ids and mirror the document id segment. */
|
|
94
|
-
static ID_FIELDS
|
|
94
|
+
static get ID_FIELDS() {
|
|
95
|
+
return getDefaultIdFields();
|
|
96
|
+
}
|
|
95
97
|
/** Method names that keep method binding priority over child signal dot access. */
|
|
96
98
|
static [GETTERS] = DEFAULT_GETTERS;
|
|
97
99
|
/** Association metadata registered for this model class. */
|
|
@@ -578,8 +580,10 @@ export class Signal extends Function {
|
|
|
578
580
|
async add(value) {
|
|
579
581
|
if (arguments.length > 1)
|
|
580
582
|
throw Error('Signal.add() expects a single argument');
|
|
581
|
-
const
|
|
582
|
-
const
|
|
583
|
+
const collection = this[SEGMENTS][0];
|
|
584
|
+
const collectionIdFields = getIdFieldsForSegments([collection, '']);
|
|
585
|
+
const id = resolveAddDocId(value, collectionIdFields, uuid);
|
|
586
|
+
const idFields = getIdFieldsForSegments([collection, id]);
|
|
583
587
|
await this[id].set(prepareAddPayload(value, idFields, id));
|
|
584
588
|
return id;
|
|
585
589
|
}
|
package/dist/orm/idFields.d.ts
CHANGED
|
@@ -2,13 +2,22 @@ import type { PathSegment } from './types/path.js';
|
|
|
2
2
|
export type IdField = string;
|
|
3
3
|
export type IdFields = readonly IdField[];
|
|
4
4
|
export type PlainObject = Record<string, unknown>;
|
|
5
|
+
export interface TeamplayRuntimeConfig {
|
|
6
|
+
idFields?: IdFields | null;
|
|
7
|
+
}
|
|
5
8
|
export declare const DEFAULT_ID_FIELDS: readonly ["_id"];
|
|
9
|
+
export declare const TEAMPLAY_RUNTIME_CONFIG_SYMBOL: unique symbol;
|
|
6
10
|
export declare function getIdFieldsForSegments(segments: PathSegment[]): IdFields;
|
|
11
|
+
export declare function configureTeamplay({ idFields }?: TeamplayRuntimeConfig): void;
|
|
12
|
+
export declare function getTeamplayConfig(): Required<TeamplayRuntimeConfig>;
|
|
13
|
+
export declare function getDefaultIdFields(): IdFields;
|
|
14
|
+
export declare function setDefaultIdFields(idFields?: IdFields): void;
|
|
15
|
+
export declare function __resetTeamplayConfigForTests(): void;
|
|
7
16
|
export declare function isPlainObject(value: unknown): value is PlainObject;
|
|
8
17
|
export declare function injectIdFields<TValue>(value: TValue, idFields: IdFields, docId: PathSegment): TValue;
|
|
9
18
|
export declare function normalizeIdFields<TValue>(value: TValue, idFields: IdFields, docId: PathSegment): TValue;
|
|
10
19
|
export declare function stripIdFields<TValue>(value: TValue, idFields: IdFields): TValue;
|
|
11
|
-
export declare function resolveAddDocId(value: unknown, getDefaultId: () => string): PathSegment;
|
|
20
|
+
export declare function resolveAddDocId(value: unknown, idFields: IdFields, getDefaultId: () => string): PathSegment;
|
|
12
21
|
export declare function prepareAddPayload<TValue extends object>(value: TValue, idFields: IdFields, docId: PathSegment): TValue;
|
|
13
22
|
export declare function isPublicDocPath(segments: unknown): segments is [string, PathSegment];
|
|
14
23
|
export declare function isIdFieldPath(segments: unknown, idFields: IdFields): segments is [string, PathSegment, string];
|
package/dist/orm/idFields.js
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
import { findModel } from "./addModel.js";
|
|
2
2
|
export const DEFAULT_ID_FIELDS = ['_id'];
|
|
3
|
+
export const TEAMPLAY_RUNTIME_CONFIG_SYMBOL = Symbol.for('teamplay.runtimeConfig');
|
|
3
4
|
export function getIdFieldsForSegments(segments) {
|
|
4
5
|
const Model = findModel(segments);
|
|
5
|
-
return Model?.ID_FIELDS ||
|
|
6
|
+
return Model?.ID_FIELDS || getDefaultIdFields();
|
|
7
|
+
}
|
|
8
|
+
export function configureTeamplay({ idFields } = {}) {
|
|
9
|
+
if (arguments.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
const config = getGlobalRuntimeConfig(true);
|
|
12
|
+
const options = (arguments[0] || {});
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(options, 'idFields')) {
|
|
14
|
+
config.idFields = idFields == null
|
|
15
|
+
? DEFAULT_ID_FIELDS
|
|
16
|
+
: normalizeIdFieldsConfig(idFields);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function getTeamplayConfig() {
|
|
20
|
+
return {
|
|
21
|
+
idFields: getDefaultIdFields()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function getDefaultIdFields() {
|
|
25
|
+
const config = getGlobalRuntimeConfig(false);
|
|
26
|
+
if (!config || !Object.prototype.hasOwnProperty.call(config, 'idFields')) {
|
|
27
|
+
return DEFAULT_ID_FIELDS;
|
|
28
|
+
}
|
|
29
|
+
if (config.idFields == null)
|
|
30
|
+
return DEFAULT_ID_FIELDS;
|
|
31
|
+
const normalized = normalizeIdFieldsConfig(config.idFields);
|
|
32
|
+
config.idFields = normalized;
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
35
|
+
export function setDefaultIdFields(idFields = DEFAULT_ID_FIELDS) {
|
|
36
|
+
getGlobalRuntimeConfig(true).idFields = normalizeIdFieldsConfig(idFields);
|
|
37
|
+
}
|
|
38
|
+
export function __resetTeamplayConfigForTests() {
|
|
39
|
+
delete getGlobalRuntimeConfigHolder()[TEAMPLAY_RUNTIME_CONFIG_SYMBOL];
|
|
6
40
|
}
|
|
7
41
|
export function isPlainObject(value) {
|
|
8
42
|
if (!value || typeof value !== 'object')
|
|
@@ -52,26 +86,28 @@ export function stripIdFields(value, idFields) {
|
|
|
52
86
|
}
|
|
53
87
|
return next;
|
|
54
88
|
}
|
|
55
|
-
export function resolveAddDocId(value, getDefaultId) {
|
|
89
|
+
export function resolveAddDocId(value, idFields, getDefaultId) {
|
|
56
90
|
if (!value || typeof value !== 'object')
|
|
57
91
|
throw Error('Signal.add() expects an object argument');
|
|
58
92
|
const payload = value;
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
93
|
+
const entries = getAddIdEntries(payload, idFields);
|
|
94
|
+
const [firstEntry] = entries;
|
|
95
|
+
const conflictEntry = firstEntry && entries.find(entry => entry.value !== firstEntry.value);
|
|
96
|
+
if (firstEntry && conflictEntry) {
|
|
97
|
+
throw Error(`Signal.add() got conflicting "${firstEntry.field}" (${JSON.stringify(firstEntry.value)}) ` +
|
|
98
|
+
`and "${conflictEntry.field}" (${JSON.stringify(conflictEntry.value)}) id fields`);
|
|
63
99
|
}
|
|
64
|
-
return
|
|
100
|
+
return firstEntry?.value ?? getDefaultId();
|
|
65
101
|
}
|
|
66
102
|
export function prepareAddPayload(value, idFields, docId) {
|
|
67
103
|
const payload = value;
|
|
68
|
-
|
|
69
|
-
payload
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
104
|
+
for (const field of idFields)
|
|
105
|
+
payload[field] = docId;
|
|
106
|
+
for (const field of LEGACY_ADD_ID_FIELDS) {
|
|
107
|
+
if (idFields.includes(field))
|
|
108
|
+
continue;
|
|
109
|
+
if (payload[field] === docId)
|
|
110
|
+
delete payload[field];
|
|
75
111
|
}
|
|
76
112
|
return value;
|
|
77
113
|
}
|
|
@@ -93,3 +129,55 @@ export function isIdFieldPath(segments, idFields) {
|
|
|
93
129
|
const last = segments[2];
|
|
94
130
|
return typeof last === 'string' && idFields.includes(last);
|
|
95
131
|
}
|
|
132
|
+
function normalizeIdFieldsConfig(idFields) {
|
|
133
|
+
if (!Array.isArray(idFields)) {
|
|
134
|
+
throw Error('Teamplay idFields config must be an array of field names');
|
|
135
|
+
}
|
|
136
|
+
const normalized = [];
|
|
137
|
+
for (const field of idFields) {
|
|
138
|
+
if (typeof field !== 'string' || field.length === 0) {
|
|
139
|
+
throw Error('Teamplay idFields config must contain only non-empty string field names');
|
|
140
|
+
}
|
|
141
|
+
if (!normalized.includes(field))
|
|
142
|
+
normalized.push(field);
|
|
143
|
+
}
|
|
144
|
+
if (normalized.length === 0) {
|
|
145
|
+
throw Error('Teamplay idFields config must contain at least one field name');
|
|
146
|
+
}
|
|
147
|
+
return Object.freeze(normalized);
|
|
148
|
+
}
|
|
149
|
+
function getAddIdEntries(payload, idFields) {
|
|
150
|
+
const fields = uniqueFields([...LEGACY_ADD_ID_FIELDS, ...idFields]);
|
|
151
|
+
const entries = [];
|
|
152
|
+
for (const field of fields) {
|
|
153
|
+
const value = payload[field];
|
|
154
|
+
if (value == null)
|
|
155
|
+
continue;
|
|
156
|
+
entries.push({ field, value: value });
|
|
157
|
+
}
|
|
158
|
+
return entries;
|
|
159
|
+
}
|
|
160
|
+
function uniqueFields(fields) {
|
|
161
|
+
const result = [];
|
|
162
|
+
for (const field of fields) {
|
|
163
|
+
if (!result.includes(field))
|
|
164
|
+
result.push(field);
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function getGlobalRuntimeConfig(create = true) {
|
|
169
|
+
const holder = getGlobalRuntimeConfigHolder();
|
|
170
|
+
let config = holder[TEAMPLAY_RUNTIME_CONFIG_SYMBOL];
|
|
171
|
+
if (config == null && create) {
|
|
172
|
+
config = {};
|
|
173
|
+
holder[TEAMPLAY_RUNTIME_CONFIG_SYMBOL] = config;
|
|
174
|
+
}
|
|
175
|
+
if (config != null && (!isPlainObject(config))) {
|
|
176
|
+
throw Error('Teamplay runtime config must be an object');
|
|
177
|
+
}
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
function getGlobalRuntimeConfigHolder() {
|
|
181
|
+
return globalThis;
|
|
182
|
+
}
|
|
183
|
+
const LEGACY_ADD_ID_FIELDS = ['id', '_id'];
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export function createBackend(options?: {}): any;
|
|
2
|
-
export function initConnection(backend: any, { fetchOnly, publicOnly, ...options }?: {
|
|
2
|
+
export function initConnection(backend: any, { fetchOnly, publicOnly, idFields, ...options }?: {
|
|
3
3
|
fetchOnly?: boolean | undefined;
|
|
4
4
|
publicOnly?: boolean | undefined;
|
|
5
5
|
}): {
|
package/dist/server.js
CHANGED
|
@@ -2,6 +2,7 @@ import createChannel from '@teamplay/channel/server';
|
|
|
2
2
|
import backendCreateBackend from '@teamplay/backend';
|
|
3
3
|
import { getModels } from "./orm/initModels.js";
|
|
4
4
|
import { connection, setConnection, setDefaultFetchOnly, setPublicOnly } from "./orm/connection.js";
|
|
5
|
+
import { configureTeamplay } from "./config.js";
|
|
5
6
|
export { default as ShareDB } from 'sharedb';
|
|
6
7
|
export { mongo, mongoClient, createMongoIndex, redis, redlock, sqlite, getRedis, Redis, getRedisOptions, redisPrefix, generateRedisPrefix } from '@teamplay/backend';
|
|
7
8
|
export function createBackend(options = {}) {
|
|
@@ -16,11 +17,13 @@ export function createBackend(options = {}) {
|
|
|
16
17
|
return backendCreateBackend(nextOptions);
|
|
17
18
|
}
|
|
18
19
|
export default createBackend;
|
|
19
|
-
export function initConnection(backend, { fetchOnly = true, publicOnly = true, ...options } = {}) {
|
|
20
|
+
export function initConnection(backend, { fetchOnly = true, publicOnly = true, idFields, ...options } = {}) {
|
|
20
21
|
if (!backend)
|
|
21
22
|
throw Error('backend is required');
|
|
22
23
|
if (connection)
|
|
23
24
|
throw Error('Connection already exists');
|
|
25
|
+
if (idFields !== undefined)
|
|
26
|
+
configureTeamplay({ idFields });
|
|
24
27
|
setConnection(backend.connect());
|
|
25
28
|
setDefaultFetchOnly(fetchOnly);
|
|
26
29
|
setPublicOnly(publicOnly);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.5.0-alpha.
|
|
3
|
+
"version": "0.5.0-alpha.31",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"teamplay-ts": "./src/connect/index.js",
|
|
27
27
|
"default": "./dist/connect/index.js"
|
|
28
28
|
},
|
|
29
|
+
"./config": {
|
|
30
|
+
"teamplay-ts": "./src/config.ts",
|
|
31
|
+
"types": "./dist/config.d.ts",
|
|
32
|
+
"default": "./dist/config.js"
|
|
33
|
+
},
|
|
29
34
|
"./server": {
|
|
30
35
|
"teamplay-ts": "./src/server.js",
|
|
31
36
|
"types": "./dist/server.d.ts",
|
|
@@ -134,5 +139,5 @@
|
|
|
134
139
|
]
|
|
135
140
|
},
|
|
136
141
|
"license": "MIT",
|
|
137
|
-
"gitHead": "
|
|
142
|
+
"gitHead": "efb7d7215b571620de2f7348ba1cd80e0cff7024"
|
|
138
143
|
}
|