@plasmicapp/data-sources 1.0.3 → 1.0.5

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/index.js CHANGED
@@ -43,6 +43,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
43
43
  mod
44
44
  ));
45
45
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
46
47
  var __async = (__this, __arguments, generator) => {
47
48
  return new Promise((resolve, reject) => {
48
49
  var fulfilled = (value) => {
@@ -65,8 +66,8 @@ var __async = (__this, __arguments, generator) => {
65
66
  };
66
67
 
67
68
  // src/index.tsx
68
- var src_exports = {};
69
- __export(src_exports, {
69
+ var index_exports = {};
70
+ __export(index_exports, {
70
71
  Fetcher: () => Fetcher,
71
72
  FetcherMeta: () => FetcherMeta,
72
73
  _StatefulQueryResult: () => StatefulQueryResult,
@@ -75,6 +76,7 @@ __export(src_exports, {
75
76
  makeCacheKey: () => makeCacheKey,
76
77
  makeQueryCacheKey: () => makeQueryCacheKey,
77
78
  normalizeData: () => normalizeData,
79
+ throwIfPlasmicUndefinedDataError: () => throwIfPlasmicUndefinedDataError,
78
80
  unstable_executePlasmicQueries: () => executePlasmicQueries,
79
81
  unstable_usePlasmicQueries: () => usePlasmicQueries,
80
82
  unstable_wrapDollarQueriesForMetadata: () => wrapDollarQueriesForMetadata,
@@ -84,59 +86,7 @@ __export(src_exports, {
84
86
  usePlasmicDataOp: () => usePlasmicDataOp,
85
87
  usePlasmicInvalidate: () => usePlasmicInvalidate
86
88
  });
87
- module.exports = __toCommonJS(src_exports);
88
-
89
- // src/serverQueries/client.ts
90
- var import_query2 = require("@plasmicapp/query");
91
- var React3 = __toESM(require("react"));
92
-
93
- // src/utils.ts
94
- function noopFn() {
95
- }
96
- function pick(obj, ...keys) {
97
- const res = {};
98
- for (const key of keys) {
99
- if (key in obj) {
100
- res[key] = obj[key];
101
- }
102
- }
103
- return res;
104
- }
105
- var tuple = (...args) => args;
106
- function mkIdMap(xs) {
107
- return new Map(xs.map((x) => tuple(x.id, x)));
108
- }
109
- function notNil(x) {
110
- return x !== null && x !== void 0;
111
- }
112
- function withoutNils(xs) {
113
- return xs.filter(notNil);
114
- }
115
- function mapRecordEntries(callback, record1, record2, record3) {
116
- return Object.entries(record1).map(([k, v1]) => {
117
- const v2 = record2 == null ? void 0 : record2[k];
118
- const v3 = record3 == null ? void 0 : record3[k];
119
- return callback(
120
- k,
121
- v1,
122
- v2,
123
- v3
124
- );
125
- });
126
- }
127
- function mapRecords(callback, record1, record2, record3) {
128
- return Object.fromEntries(
129
- mapRecordEntries(
130
- (k, v1, v2, v3) => [k, callback(k, v1, v2, v3)],
131
- record1,
132
- record2,
133
- record3
134
- )
135
- );
136
- }
137
-
138
- // src/serverQueries/common.ts
139
- var import_react2 = __toESM(require("react"));
89
+ module.exports = __toCommonJS(index_exports);
140
90
 
141
91
  // src/common.ts
142
92
  var import_query = require("@plasmicapp/query");
@@ -145,6 +95,11 @@ var import_react = __toESM(require("react"));
145
95
  function isPlasmicUndefinedDataErrorPromise(x) {
146
96
  return !!x && typeof x === "object" && (x == null ? void 0 : x.plasmicType) === "PlasmicUndefinedDataError";
147
97
  }
98
+ function throwIfPlasmicUndefinedDataError(err) {
99
+ if (isPlasmicUndefinedDataErrorPromise(err)) {
100
+ throw err;
101
+ }
102
+ }
148
103
  function tagPlasmicUndefinedDataErrorPromise(promise) {
149
104
  promise.plasmicType = "PlasmicUndefinedDataError";
150
105
  promise.message = "Query is not done";
@@ -314,7 +269,57 @@ function usePlasmicFetch(key, resolvedParams, fetcherFn, resultMapper, undefined
314
269
  ]);
315
270
  }
316
271
 
272
+ // src/serverQueries/client.ts
273
+ var import_query2 = require("@plasmicapp/query");
274
+ var React3 = __toESM(require("react"));
275
+
276
+ // src/utils.ts
277
+ function noopFn() {
278
+ }
279
+ function pick(obj, ...keys) {
280
+ const res = {};
281
+ for (const key of keys) {
282
+ if (key in obj) {
283
+ res[key] = obj[key];
284
+ }
285
+ }
286
+ return res;
287
+ }
288
+ var tuple = (...args) => args;
289
+ function mkIdMap(xs) {
290
+ return new Map(xs.map((x) => tuple(x.id, x)));
291
+ }
292
+ function notNil(x) {
293
+ return x !== null && x !== void 0;
294
+ }
295
+ function withoutNils(xs) {
296
+ return xs.filter(notNil);
297
+ }
298
+ function mapRecordEntries(callback, record1, record2, record3) {
299
+ return Object.entries(record1).map(([k, v1]) => {
300
+ const v2 = record2 == null ? void 0 : record2[k];
301
+ const v3 = record3 == null ? void 0 : record3[k];
302
+ return callback(
303
+ k,
304
+ v1,
305
+ v2,
306
+ v3
307
+ );
308
+ });
309
+ }
310
+ function mapRecords(callback, record1, record2, record3) {
311
+ return Object.fromEntries(
312
+ mapRecordEntries(
313
+ (k, v1, v2, v3) => [k, callback(k, v1, v2, v3)],
314
+ record1,
315
+ record2,
316
+ record3
317
+ )
318
+ );
319
+ }
320
+
317
321
  // src/serverQueries/common.ts
322
+ var import_react2 = __toESM(require("react"));
318
323
  function createDollarQueries(queryNames) {
319
324
  return Object.fromEntries(
320
325
  queryNames.map((queryName) => {
@@ -324,7 +329,9 @@ function createDollarQueries(queryNames) {
324
329
  }
325
330
  var StatefulQueryResult = class {
326
331
  constructor() {
327
- this.listeners = /* @__PURE__ */ new Set();
332
+ __publicField(this, "current");
333
+ __publicField(this, "settable");
334
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
328
335
  this.current = { state: "initial", key: null };
329
336
  this.settable = new SettablePromise();
330
337
  tagPlasmicUndefinedDataErrorPromise(this.settable.promise);
@@ -470,8 +477,8 @@ function resolveParams(params) {
470
477
  function wrapDollarQueriesForMetadata($queries, ifUndefined, ifError) {
471
478
  return wrapDollarQueriesWithFallbacks(
472
479
  $queries,
473
- ifUndefined != null ? ifUndefined : () => "\u2026",
474
- ifError != null ? ifError : () => "[ERROR]"
480
+ ifUndefined != null ? ifUndefined : (() => "\u2026"),
481
+ ifError != null ? ifError : (() => "[ERROR]")
475
482
  );
476
483
  }
477
484
  function wrapDollarQueriesWithFallbacks($queries, ifUndefined, ifError) {
@@ -482,9 +489,9 @@ function wrapDollarQueriesWithFallbacks($queries, ifUndefined, ifError) {
482
489
  }
483
490
  var FallbackQueryResult = class {
484
491
  constructor($query, ifUndefined, ifError) {
485
- this.$query = $query;
486
- this.ifUndefined = ifUndefined;
487
- this.ifError = ifError;
492
+ __publicField(this, "$query", $query);
493
+ __publicField(this, "ifUndefined", ifUndefined);
494
+ __publicField(this, "ifError", ifError);
488
495
  }
489
496
  get key() {
490
497
  return this.$query.key;
@@ -513,8 +520,8 @@ function createConstantProxy(constant) {
513
520
  }
514
521
  var SyncPromise = class {
515
522
  constructor(promise) {
516
- this.promise = promise;
517
- this.result = void 0;
523
+ __publicField(this, "promise", promise);
524
+ __publicField(this, "result");
518
525
  promise.then(
519
526
  (value) => {
520
527
  this.result = {
@@ -546,6 +553,9 @@ function shallowEqualRecords(a, b) {
546
553
  }
547
554
  var SettablePromise = class {
548
555
  constructor() {
556
+ __publicField(this, "promise");
557
+ __publicField(this, "_resolve");
558
+ __publicField(this, "_reject");
549
559
  this.promise = new Promise((resolve, reject) => {
550
560
  this._resolve = resolve;
551
561
  this._reject = reject;
@@ -699,7 +709,7 @@ function usePlasmicQueries(tree, $props, $ctx, $state) {
699
709
  }
700
710
  }
701
711
  let cleanup = false;
702
- const loop = () => __async(this, null, function* () {
712
+ const loop = () => __async(null, null, function* () {
703
713
  while (true) {
704
714
  initPlasmicQueriesSync(
705
715
  $queryStates,
@@ -1250,7 +1260,7 @@ function makeCacheKey(dataOp, opts) {
1250
1260
  }
1251
1261
  function usePlasmicInvalidate() {
1252
1262
  const { cache, fallback, mutate } = (0, import_query4.usePlasmicDataConfig)();
1253
- return (invalidatedKeys) => __async(this, null, function* () {
1263
+ return (invalidatedKeys) => __async(null, null, function* () {
1254
1264
  const getKeysToInvalidate = () => {
1255
1265
  var _a, _b;
1256
1266
  if (!invalidatedKeys) {
@@ -1288,7 +1298,7 @@ function usePlasmicInvalidate() {
1288
1298
  if (keys.length === 0) {
1289
1299
  return;
1290
1300
  }
1291
- const invalidateKey = (key) => __async(this, null, function* () {
1301
+ const invalidateKey = (key) => __async(null, null, function* () {
1292
1302
  const studioInvalidate = globalThis.__PLASMIC_MUTATE_DATA_OP;
1293
1303
  if (studioInvalidate) {
1294
1304
  yield studioInvalidate(key);
@@ -1344,8 +1354,8 @@ function usePlasmicDataOp(dataOp, opts) {
1344
1354
  function usePlasmicDataMutationOp(dataOp) {
1345
1355
  const ctx = (0, import_data_sources_context.usePlasmicDataSourceContext)();
1346
1356
  const userToken = ctx == null ? void 0 : ctx.userAuthToken;
1347
- const getRealDataOp = React4.useCallback(() => __async(this, null, function* () {
1348
- const tryGetRealDataOp = () => __async(this, null, function* () {
1357
+ const getRealDataOp = React4.useCallback(() => __async(null, null, function* () {
1358
+ const tryGetRealDataOp = () => __async(null, null, function* () {
1349
1359
  const resolved = resolveDataOp(dataOp);
1350
1360
  if (!resolved) {
1351
1361
  return null;
@@ -1358,7 +1368,7 @@ function usePlasmicDataMutationOp(dataOp) {
1358
1368
  });
1359
1369
  return yield tryGetRealDataOp();
1360
1370
  }), [dataOp]);
1361
- return React4.useCallback(() => __async(this, null, function* () {
1371
+ return React4.useCallback(() => __async(null, null, function* () {
1362
1372
  var _a;
1363
1373
  const { sourceId, opId, userArgs } = (_a = yield getRealDataOp()) != null ? _a : {};
1364
1374
  if (!sourceId || !opId) {