@_linked/server 3.1.0 → 3.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @\_linked/server
2
2
 
3
+ ## 3.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#187](https://github.com/linked-fw/server/pull/187) [`33a34ea`](https://github.com/linked-fw/server/commit/33a34eaf62deb591140542d8d324ae3ea0eb74a4) Thanks [@flyon](https://github.com/flyon)! - A second copy of this package in one process no longer falls back to defaults: `server.rawQueries`, `server.rpcExposure` and the host's query catalog resolver live on `globalThis` (core's `sharedState`), and the process setup (cookie-jar `fetch`, `process` error listeners) runs once per process. `RemoteDatasetError`, its two subclasses and `FatalStartupError` are branded, so `isLinkedError(err, RemoteDatasetUnreachableError)` from `@_linked/core` matches one thrown by another copy. Requires `@_linked/core` 2.36.0.
8
+
9
+ ## 3.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#185](https://github.com/linked-fw/server/pull/185) [`0525786`](https://github.com/linked-fw/server/commit/05257867d02ad8057a8691f61e94f1bbb937c56d) Thanks [@flyon](https://github.com/flyon)! - `RemoteDataset.init()` now resolves the data server's `ping` body, and the store keeps it as the readonly `info` (type `RemoteDatasetPingInfo`). A gateway that names the dataset it serves (for example `{ok, projectId, branchName, dataset, forked}`) lets an app log at startup which dataset its data goes to. The no-url form resolves `undefined`, as before.
14
+
3
15
  ## 3.1.0
4
16
 
5
17
  ### Minor Changes
@@ -30,6 +30,7 @@ import { ShapeProvider } from '@_linked/server-utils/utils/ShapeProvider';
30
30
  import { getCallContext, httpCallContext, runAsSystem, runInHttpContext, runWithCallContext, } from '@_linked/server-utils/utils/CallContext';
31
31
  import { Shape } from '@_linked/core/shapes/Shape';
32
32
  import { LinkedErrorLogging } from '@_linked/core/utils/LinkedErrorLogging';
33
+ import { sharedState } from '@_linked/core/utils/sharedState';
33
34
  import { FileStorePurposes, LinkedFileStorage, } from '@_linked/core/utils/LinkedFileStorage';
34
35
  import { getResizedImagesStore } from '../utils/resizedImagesPurpose.js';
35
36
  import { paint } from '../utils/paint.js';
@@ -146,30 +147,43 @@ import { setRawQueriesMode } from '../utils/rawQueries.js';
146
147
  //prevent errors in node.js when (s)css files are imported in js
147
148
  const isProduction = process.env.NODE_ENV === 'production';
148
149
  const isDevelopment = process.env.NODE_ENV === 'development';
149
- // Install a global fetch that persists cookies across redirects using a CookieJar.
150
- // This ensures server-side requests behave more like browsers when handling Set-Cookie + redirects.
151
- const __lincdCookieJar = new CookieJar();
152
- // Wrap native fetch with fetch-cookie so it reads/writes cookies in the jar.
153
- const __lincdFetchWithCookies = fetchCookie(fetch, __lincdCookieJar);
154
- // Expose (optionally) for debugging/tests; not required by app logic.
155
- globalThis.__lincdCookieJar = __lincdCookieJar;
156
- // Set the global fetch used throughout the server code path
157
- globalThis.fetch = __lincdFetchWithCookies;
158
- process.on('uncaughtException', (err) => {
159
- console.warn(paint('red', 'Asynchronous error caught.'));
160
- console.error(err);
161
- // error logging
162
- LinkedErrorLogging.log(err);
163
- });
164
- process.on('unhandledRejection', (err) => {
165
- console.warn(paint('red', 'Unhandled rejection caught.'));
166
- console.error(err);
167
- // error logging
168
- LinkedErrorLogging.log(err);
169
- });
170
- process.on('warning', (e) => console.warn(e.stack));
171
- //allow more listeners for when we have many concurrent users
172
- events.EventEmitter.prototype.setMaxListeners(500);
150
+ // The process-wide setup below runs once per process, not once per copy of this module: a
151
+ // second copy would wrap the already-wrapped fetch in a second cookie jar and register every
152
+ // process listener twice. See
153
+ // https://github.com/linked-fw/cli/blob/main/docs/architecture/shared-state-and-error-brands.md.
154
+ const processSetup = sharedState('@_linked/server', 'LinkedServer.processSetup', () => ({
155
+ done: false,
156
+ }));
157
+ if (!processSetup.done) {
158
+ processSetup.done = true;
159
+ installProcessSetup();
160
+ }
161
+ function installProcessSetup() {
162
+ // Install a global fetch that persists cookies across redirects using a CookieJar.
163
+ // This ensures server-side requests behave more like browsers when handling Set-Cookie + redirects.
164
+ const __lincdCookieJar = new CookieJar();
165
+ // Wrap native fetch with fetch-cookie so it reads/writes cookies in the jar.
166
+ const __lincdFetchWithCookies = fetchCookie(fetch, __lincdCookieJar);
167
+ // Expose (optionally) for debugging/tests; not required by app logic.
168
+ globalThis.__lincdCookieJar = __lincdCookieJar;
169
+ // Set the global fetch used throughout the server code path
170
+ globalThis.fetch = __lincdFetchWithCookies;
171
+ process.on('uncaughtException', (err) => {
172
+ console.warn(paint('red', 'Asynchronous error caught.'));
173
+ console.error(err);
174
+ // error logging
175
+ LinkedErrorLogging.log(err);
176
+ });
177
+ process.on('unhandledRejection', (err) => {
178
+ console.warn(paint('red', 'Unhandled rejection caught.'));
179
+ console.error(err);
180
+ // error logging
181
+ LinkedErrorLogging.log(err);
182
+ });
183
+ process.on('warning', (e) => console.warn(e.stack));
184
+ //allow more listeners for when we have many concurrent users
185
+ events.EventEmitter.prototype.setMaxListeners(500);
186
+ }
173
187
  // const jsdom = require("jsdom");
174
188
  // const { JSDOM } = jsdom;
175
189
  // const { document } = (new JSDOM(`...`)).window;