@hatk/hatk 0.0.1-alpha.51 → 0.0.1-alpha.53

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 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAgB,MAAM,WAAW,CAAA;AAEnF;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CA0BrE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBzF;AAED,wFAAwF;AACxF,eAAO,MAAM,WAAW,UAavB,CAAA;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAChD,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,6EA4BjF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAgB,MAAM,WAAW,CAAA;AAEnF;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CA0BrE;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBzF;AAED,wFAAwF;AACxF,eAAO,MAAM,WAAW,UAcvB,CAAA;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,EAChD,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,IAAI,KAAK,IAAI,6EA4BjF"}
package/dist/adapter.js CHANGED
@@ -60,7 +60,8 @@ export const HATK_ROUTES = [
60
60
  '/xrpc/',
61
61
  '/oauth/',
62
62
  '/oauth-client-metadata.json',
63
- '/.well-known/',
63
+ '/.well-known/oauth-authorization-server',
64
+ '/.well-known/oauth-protected-resource',
64
65
  '/og/',
65
66
  '/admin',
66
67
  '/repos',
@@ -214,13 +214,16 @@ function buildChildExpectedCols(columns) {
214
214
  }
215
215
  export async function migrateSchema(tableSchemas) {
216
216
  const changes = [];
217
+ const newCollections = new Set();
217
218
  for (const schema of tableSchemas) {
218
219
  if (schema.columns.length === 0)
219
220
  continue; // generic JSON storage, skip
220
221
  const tableName = schema.collection;
221
222
  const existingCols = await getExistingColumns(tableName);
222
- if (existingCols.size === 0)
223
+ if (existingCols.size === 0) {
224
+ newCollections.add(schema.collection);
223
225
  continue; // table just created, nothing to migrate
226
+ }
224
227
  // Expected columns: base columns (uri, cid, did, indexed_at) + schema columns
225
228
  const expectedCols = new Map();
226
229
  expectedCols.set('uri', 'TEXT');
@@ -281,22 +284,16 @@ export async function migrateSchema(tableSchemas) {
281
284
  if (changes.length > 0) {
282
285
  await applyMigrationChanges(changes);
283
286
  }
284
- // Check for empty collection tables these are newly added and need backfill
285
- // Skip on fresh DB (no repos yet) since backfill runs naturally
286
- const [hasRepos] = await all(`SELECT 1 FROM _repos LIMIT 1`);
287
- if (hasRepos) {
288
- for (const schema of tableSchemas) {
289
- if (schema.columns.length === 0)
290
- continue;
291
- try {
292
- const [row] = await all(`SELECT 1 FROM ${schema.tableName} LIMIT 1`);
293
- if (!row) {
294
- await run(`UPDATE _repos SET status = 'pending' WHERE status = 'active'`);
295
- emit('migration', 'new_collection', { collection: schema.collection });
296
- break; // only need to mark once
297
- }
287
+ // Trigger backfill only for genuinely new collections (tables created this startup)
288
+ // Previously this checked ALL empty tables, which caused infinite resync loops
289
+ // for collections that are legitimately empty (e.g. blocks when nobody has blocked)
290
+ if (newCollections.size > 0) {
291
+ const [hasRepos] = await all(`SELECT 1 FROM _repos LIMIT 1`);
292
+ if (hasRepos) {
293
+ await run(`UPDATE _repos SET status = 'pending' WHERE status = 'active'`);
294
+ for (const collection of newCollections) {
295
+ emit('migration', 'new_collection', { collection });
298
296
  }
299
- catch { }
300
297
  }
301
298
  }
302
299
  return changes;
@@ -1 +1 @@
1
- {"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../src/push.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,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,IAAI,CAAC,CAAA;CAC9C;AAOD,iEAAiE;AACjE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CASpE;AAED,iDAAiD;AACjD,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,IAAI,aAAa,CAElD;AAgJD,4DAA4D;AAC5D,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/F;AAED,2BAA2B;AAC3B,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;AAED,6CAA6C;AAC7C,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/E"}
package/dist/push.js CHANGED
@@ -66,8 +66,15 @@ function getHttp2Session() {
66
66
  const host = pushConfig?.apns.production !== false
67
67
  ? 'https://api.push.apple.com'
68
68
  : 'https://api.sandbox.push.apple.com';
69
- http2Session = connect(host);
70
- http2Session.on('error', () => {
69
+ emit('push', 'connecting', { host });
70
+ http2Session = connect(host, {
71
+ peerMaxConcurrentStreams: 100,
72
+ });
73
+ http2Session.on('connect', () => {
74
+ emit('push', 'connected', { host });
75
+ });
76
+ http2Session.on('error', (err) => {
77
+ emit('push', 'connection_error', { host, error: err.message });
71
78
  http2Session = null;
72
79
  });
73
80
  http2Session.on('close', () => {
@@ -111,10 +118,13 @@ async function sendToApns(token, payload, jwt, original) {
111
118
  }
112
119
  return new Promise((resolve) => {
113
120
  const req = session.request(headers);
121
+ let settled = false;
122
+ const done = () => { if (settled)
123
+ return; settled = true; resolve(); };
114
124
  req.setTimeout(15_000, () => {
115
125
  req.close();
116
126
  emit('push', 'send_error', { did: original.did, error: 'APNs request timed out' });
117
- resolve();
127
+ done();
118
128
  });
119
129
  let status = 0;
120
130
  let body = '';
@@ -125,6 +135,8 @@ async function sendToApns(token, payload, jwt, original) {
125
135
  body += chunk.toString();
126
136
  });
127
137
  req.on('end', async () => {
138
+ if (settled)
139
+ return;
128
140
  if (status === 200) {
129
141
  emit('push', 'sent', { did: original.did, token: token.slice(0, 8) + '...' });
130
142
  }
@@ -140,11 +152,13 @@ async function sendToApns(token, payload, jwt, original) {
140
152
  body: body.slice(0, 200),
141
153
  });
142
154
  }
143
- resolve();
155
+ done();
144
156
  });
145
157
  req.on('error', (err) => {
158
+ if (settled)
159
+ return;
146
160
  emit('push', 'send_error', { did: original.did, error: err.message });
147
- resolve();
161
+ done();
148
162
  });
149
163
  req.write(payload);
150
164
  req.end();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hatk/hatk",
3
- "version": "0.0.1-alpha.51",
3
+ "version": "0.0.1-alpha.53",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "hatk": "dist/cli.js"