@powersync/service-core 0.0.0-dev-20251124070259 → 0.0.0-dev-20251126121420

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.
@@ -1,12 +1,10 @@
1
1
  import { BasicRouterRequest, Context, SyncRulesBucketStorage } from '@/index.js';
2
- import { RouterResponse, ServiceError, logger } from '@powersync/lib-services-framework';
2
+ import { logger, RouterResponse, ServiceError } from '@powersync/lib-services-framework';
3
3
  import { SqlSyncRules } from '@powersync/service-sync-rules';
4
4
  import { Readable, Writable } from 'stream';
5
5
  import { pipeline } from 'stream/promises';
6
6
  import { describe, expect, it } from 'vitest';
7
- import winston from 'winston';
8
7
  import { syncStreamed } from '../../../src/routes/endpoints/sync-stream.js';
9
- import { DEFAULT_PARAM_LOGGING_FORMAT_OPTIONS, formatParamsForLogging } from '../../../src/util/param-logging.js';
10
8
  import { mockServiceContext } from './mocks.js';
11
9
 
12
10
  describe('Stream Route', () => {
@@ -79,88 +77,6 @@ describe('Stream Route', () => {
79
77
  const r = await drainWithTimeout(stream).catch((error) => error);
80
78
  expect(r.message).toContain('Simulated storage error');
81
79
  });
82
-
83
- it('logs the application metadata', async () => {
84
- const storage = {
85
- getParsedSyncRules() {
86
- return new SqlSyncRules('bucket_definitions: {}');
87
- },
88
- watchCheckpointChanges: async function* (options) {
89
- throw new Error('Simulated storage error');
90
- }
91
- } as Partial<SyncRulesBucketStorage>;
92
- const serviceContext = mockServiceContext(storage);
93
-
94
- // Create a custom format to capture log info objects (which include defaultMeta)
95
- // Winston merges defaultMeta into the info object during formatting
96
- const capturedLogs: any[] = [];
97
- const captureFormat = winston.format((info) => {
98
- // Capture the info object which includes defaultMeta merged in
99
- capturedLogs.push({ ...info });
100
- return info;
101
- });
102
-
103
- // Create a test logger with the capture format
104
- const testLogger = winston.createLogger({
105
- format: winston.format.combine(captureFormat(), winston.format.json()),
106
- transports: [new winston.transports.Console()]
107
- });
108
-
109
- const context: Context = {
110
- logger: testLogger,
111
- service_context: serviceContext,
112
- token_payload: {
113
- exp: new Date().getTime() / 1000 + 10000,
114
- iat: new Date().getTime() / 1000 - 10000,
115
- sub: 'test-user'
116
- }
117
- };
118
-
119
- const request: BasicRouterRequest = {
120
- headers: {
121
- 'accept-encoding': 'gzip'
122
- },
123
- hostname: '',
124
- protocol: 'http'
125
- };
126
-
127
- const inputMeta = {
128
- test: 'test',
129
- long_meta: 'a'.repeat(1000)
130
- };
131
-
132
- const response = await (syncStreamed.handler({
133
- context,
134
- params: {
135
- app_metadata: inputMeta,
136
- parameters: {
137
- user_name: 'bob'
138
- }
139
- },
140
- request
141
- }) as Promise<RouterResponse>);
142
- expect(response.status).toEqual(200);
143
- const stream = response.data as Readable;
144
- const r = await drainWithTimeout(stream).catch((error) => error);
145
- expect(r.message).toContain('Simulated storage error');
146
-
147
- // Find the "Sync stream started" log entry
148
- const syncStartedLog = capturedLogs.find((log) => log.message === 'Sync stream started');
149
- expect(syncStartedLog).toBeDefined();
150
-
151
- // Verify that app_metadata from defaultMeta is present in the log
152
- expect(syncStartedLog?.app_metadata).toBeDefined();
153
- expect(syncStartedLog?.app_metadata).toEqual(formatParamsForLogging(inputMeta));
154
- // Should trim long metadata
155
- expect(syncStartedLog?.app_metadata.long_meta.length).toEqual(
156
- DEFAULT_PARAM_LOGGING_FORMAT_OPTIONS.maxStringLength
157
- );
158
-
159
- // Verify the explicit log parameters
160
- expect(syncStartedLog?.client_params).toEqual({
161
- user_name: 'bob'
162
- });
163
- });
164
80
  });
165
81
  });
166
82