Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Jul 21, 2024
1 parent efa81f7 commit f0efaf8
Show file tree
Hide file tree
Showing 50 changed files with 810 additions and 190 deletions.
10 changes: 10 additions & 0 deletions .deploy/default/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"public": {

},
"packages": {
"mongo": {
"options": {
"minPoolSize": 100,
"maxPoolSize": 1000
},
"oplogUrl": "",
"oplogIncludeCollections": []
}
}
}
15 changes: 15 additions & 0 deletions .deploy/ghcr.io/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"public": {

},
"packages": {
"mongo": {
"options": {
"minPoolSize": 100,
"maxPoolSize": 1000
},
"oplogUrl": "",
"oplogIncludeCollections": []
}
}
}
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ PORT=3000

MONGO_VERSION=5.0
MONGO_URL=mongodb://patient-db:27017/meteor
MONGO_OPLOG_URL=""

HTTP_FORWARDED_COUNT=1
8 changes: 8 additions & 0 deletions .github/workflows/ci:build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
- uses: actions/checkout@v4
with:
sparse-checkout: |
settings.json
scripts/healthcheck.cjs
scripts/assert-replica-set.js
.github/actions/docker/container/is-healthy/action.yml
Expand Down Expand Up @@ -176,11 +177,18 @@ jobs:
container: mongodb
timeout: 60

- name: Configure server
id: configure-server
run: |
echo "settings=$(cat settings.json)" >> "${GITHUB_OUTPUT}"
- name: Run server
id: server
env:
ROOT_URL: http://localhost
MONGO_URL: mongodb://localhost:27017/meteor
MONGO_OPLOG_URL: ""
METEOR_SETTINGS: ${{ steps.configure-server.outputs.meteor-settings }}
PORT: 3000
run: |
cd dist
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/ci:build:image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
- uses: actions/checkout@v4
with:
sparse-checkout: |
settings.json
scripts/assert-replica-set.js
.github/actions/docker/container/ip-address/action.yml
.github/actions/docker/container/is-healthy/action.yml
Expand Down Expand Up @@ -138,10 +139,17 @@ jobs:
container: mongodb
timeout: 60

- name: Configure server
id: configure-server
run: |
echo "settings=$(cat settings.json)" >> "${GITHUB_OUTPUT}"
- name: Run server
env:
ROOT_URL: http://localhost
MONGO_URL: mongodb://mongodb:27017/meteor
MONGO_OPLOG_URL: ""
METEOR_SETTINGS: ${{ steps.configure-server.outputs.meteor-settings }}
PORT: 3000
run: |
docker container run \
Expand All @@ -151,6 +159,8 @@ jobs:
--publish "${PORT}:${PORT}" \
--env "ROOT_URL=${ROOT_URL}" \
--env "MONGO_URL=${MONGO_URL}" \
--env "MONGO_OPLOG_URL=${MONGO_OPLOG_URL}" \
--env "METEOR_SETTINGS=${METEOR_SETTINGS}" \
--env "PORT=${PORT}" \
--name server \
${{ steps.server-image-url.outputs.url }}
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ EXPOSE 3000
ENV \
ROOT_URL="http://localhost" \
PORT="3000" \
MONGO_URL="mongodb://localhost:27017/meteor"
MONGO_URL="mongodb://localhost:27017/meteor" \
MONGO_OPLOG_URL=""

HEALTHCHECK \
--interval=21s \
Expand Down
2 changes: 2 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
- ROOT_URL=${ROOT_URL}
- PORT=${PORT}
- MONGO_URL=${MONGO_URL}
- MONGO_OPLOG_URL=${MONGO_OPLOG_URL}
- METEOR_SETTINGS=${METEOR_SETTINGS}
- HTTP_FORWARDED_COUNT=${HTTP_FORWARDED_COUNT}
depends_on:
patient-db:
Expand Down
57 changes: 44 additions & 13 deletions imports/_test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,64 @@ export const dropOwner = ({owner, ...rest}) => {

export const dropOwners = (x) => x.map(dropOwner);

export const create = (template, extra, hasExtra: boolean) => {
type Created<T> = T extends {[K in keyof T]: T[K]}
? {[K in keyof T]: Created<T[K]>}
: T extends () => any
? ReturnType<T>
: never;

type Extra<T> = T extends any[]
? Created<T>
: T extends {[K in keyof T]: T[K]}
? Partial<Created<T>>
: T extends () => any
? ReturnType<T>
: never;

export function create<T extends () => any>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T>;
export function create<T extends {[K in keyof T]: T[K]}>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T>;

export function create<T>(
template: T,
extra?: Extra<T>,
hasExtra?: boolean,
): Created<T> {
if (typeof template === 'function') return hasExtra ? extra : template();
if (Array.isArray(template)) {
return template
return (template as Array<T[keyof T]>)
.map((x, i) =>
create(
x,
extra?.[i],
Object.prototype.hasOwnProperty.call(extra ?? [], i),
),
)
.concat(extra?.slice(template.length) ?? []);
.concat(extra?.slice(template.length) ?? []) as Created<T>;
}

return Object.fromEntries(
(extra === undefined ? [] : Object.entries(extra)).concat(
Object.entries(template).map(([key, value]) => [
key,
create(
value,
extra?.[key],
Object.prototype.hasOwnProperty.call(extra ?? {}, key),
),
]),
Object.entries(template as {[K in keyof T]: T[K]}).map(
<V>([key, value]: [string, V]) => [
key,
create(
value,
extra?.[key],
Object.prototype.hasOwnProperty.call(extra ?? {}, key),
),
],
),
),
);
};
) as Created<T>;
}

export const findOneOrThrow = async <T extends Document, U = T>(
collection: Collection<T, U>,
Expand Down
2 changes: 1 addition & 1 deletion imports/api/collection/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import define from './define';

type SettingDocument = {
export type SettingDocument = {
owner: string;
key: string;
value: any;
Expand Down
10 changes: 6 additions & 4 deletions imports/api/createTagCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const createTagCollection = <
const isLoading = useSubscription(parentPublication, query);
const loading = isLoading();

const results = useCursor(
const {results} = useCursor(
() => Parent.find(filter as Selector<P>, options),
[name, JSON.stringify(options)],
);
Expand Down Expand Up @@ -246,12 +246,14 @@ const createTagCollection = <

const useTagStats = (name) => {
const isLoading = useSubscription(_statsPublication, name);
const loading = isLoading();
const loadingSubscription = isLoading();

const result = useItem(Stats, {name}, undefined, [name]);
const {loading: loadingResult, result} = useItem(Stats, {name}, undefined, [
name,
]);

return {
loading,
loading: loadingSubscription || loadingResult,
result,
};
};
Expand Down
18 changes: 11 additions & 7 deletions imports/api/makeCachedFindOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ const makeCachedFindOne =
const ref = useRef(init);

const isLoading = useSubscription(publication, query);
const loading = isLoading();
const loadingSubscription = isLoading();

const [selector, options] = queryToSelectorOptionsPair(query);
const upToDate = useItem(loading ? null : collection, selector, options, [
loading,
...deps,
]);
const {
loading: loadingResult,
found,
result: upToDate,
} = useItem(collection, selector, options, [loadingSubscription, ...deps]);

const found = Boolean(upToDate);
const fields = {...ref.current, ...upToDate};
ref.current = fields;

return {loading, found, fields} as ReturnValue<U, I>;
return {
loading: loadingSubscription || loadingResult,
found,
fields,
} as ReturnValue<U, I>;
};

export default makeCachedFindOne;
11 changes: 6 additions & 5 deletions imports/api/makeCachedFindOneOpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {type DependencyList, useState, useEffect} from 'react';
import useRandom from '../ui/hooks/useRandom';

import type Publication from './publication/Publication';
import subscribe, {type SubscriptionError} from './publication/subscribe';
import subscribe from './publication/subscribe';
import type Options from './query/Options';
import type Collection from './Collection';
import type Document from './Document';
import observeSetChanges from './query/observeSetChanges';
import type Filter from './query/Filter';
import {type WatchHandle} from './query/watch';
import type SubscriptionError from './publication/SubscriptionError';
import stopSubscription from './publication/stopSubscription';

/**
* WARNING: Does not work properly if used multiple times with the same
Expand Down Expand Up @@ -44,8 +46,8 @@ const makeCachedFindOneOpt =
let queryHandle: WatchHandle<T>;
let stopped = false;
const handle = subscribe(publication, filter, options, {
async onStop(e: SubscriptionError) {
console.debug('onStop()', {e, queryHandle});
async onStop(error?: SubscriptionError) {
console.debug('onStop()', {error, queryHandle});
stopped = true;
if (queryHandle !== undefined) await queryHandle.emit('stop');
else reset();
Expand Down Expand Up @@ -75,8 +77,7 @@ const makeCachedFindOneOpt =
});

return () => {
console.debug('handle.stop()');
handle.stop();
stopSubscription(handle);
};
}, [key, ...deps]);

Expand Down
2 changes: 1 addition & 1 deletion imports/api/makeDebouncedResultsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const makeDebouncedResultsQuery =
const loading = isLoading();

const [selector, options] = queryToSelectorOptionsPair(query);
const currentValue = useCursor(
const {results: currentValue} = useCursor(
() => collection.find(selector, options),
deps,
);
Expand Down
5 changes: 4 additions & 1 deletion imports/api/makeFilteredCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ const makeFilteredCollection = <
) => {
const isLoading = useSubscription(publication, null, options ?? null);
const loading = isLoading();
const results = useCursor(() => Filtered.find(hookSelector, options), deps);
const {results} = useCursor(
() => Filtered.find(hookSelector, options),
deps,
);
return {loading, results};
};
};
Expand Down
19 changes: 11 additions & 8 deletions imports/api/makeFindOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ const makeFindOne =
deps: DependencyList,
): ReturnValue<U, I> => {
const isLoading = useSubscription(publication, query);
const loading = isLoading();
const loadingSubscription = isLoading();

const [selector, options] = queryToSelectorOptionsPair(query);
const upToDate = useItem(loading ? null : collection, selector, options, [
loading,
...deps,
]);

const found = Boolean(upToDate);
const {
loading: loadingResult,
found,
result: upToDate,
} = useItem(collection, selector, options, [loadingSubscription, ...deps]);

const fields = {...init, ...upToDate};

return {loading, found, fields} as ReturnValue<U, I>;
return {
loading: loadingSubscription || loadingResult,
found,
fields,
} as ReturnValue<U, I>;
};

export default makeFindOne;
Loading

0 comments on commit f0efaf8

Please sign in to comment.